facebookfacebook-graph-apifacebook-php-sdkfacebook-invite

Invite facebook friends to our application


I'm using facebook php sdk and developing an application where in I wanna invite facebook friends for some link by sending message to them. So whoever I invited, I wanna save those facebook Ids into my database. Please suggest some solutions to send message to each facebook friend and get his facebbokId. The work is more appreciated.


Solution

  • I think your using php sdk ...

    By using the below PHP code you can get the friends list from the facebook

                    <?php
                    $facebook = new Facebook(array(
                          'appId'  => 'CLIENT_ID',
                          'secret' => 'SECRET_KEY',
                    ));          
                    $access_token = $facebook->getAccessToken();
                    $user = $facebook->getUser();
                    $result =file_get_contents('https://graph.facebook.com/'.$user.'/friends?access_token='.$access_token.'');  
                                        print_r($result);
                    ?>
    

    After getting the friends list data from the facebook by using sdk..If you want to store the details you store it into your database

    Javascriptcode:

    $.ajax({
                            type:'POST',                            
                            url:'/action_comes_here',
                            data:{},
                            success: function()
                            {
                                var user_ids = array('14545456','5695695456'); //
                                FB.ui({method: 'apprequests',
                                      app_id:'CLIENT_ID',
                                      message: 'TITLE',
                                      data:{},
                                      to: user_ids,   
                                    },
                                    function(response) { 
                                        if(response){
                                            ///SUCCESS HERE
                                        }
                                        else
                                        {
                                            ///FALIURE COMES HERE
                                        }
                                    });
                                },
                                error: function(){
                                                alert("Something went wrong ... Please Try again");
    
                                }
                     });            
    

    Thanks Sakthi