Manoj Mansukhani
Manoj Mansukhani

Reputation: 1

How to send a Facebook application request to retrieve data on accepting?

Need to send a request for a Facebook application so that when the user accepts the request I need to retrieve the name of the person who sent it and the name of the person who accepted it. Can someone please share examples of the codr

Upvotes: 0

Views: 553

Answers (2)

Smita
Smita

Reputation: 4634

while sending invite you can add any data to track, let say you want to send sender_name so your send request function will be like:

FB.ui({
        method: 'apprequests',
        message: "has invited you to the app",
        filters:['app_non_users'],
        data: sender_name
    }, function (response) {
    });

and when the receiver comes to your application clicking the request notification sent, then you can retrieve data and delete the request in php as below:

if(isset($_GET['request_ids']))
   {
       $request_ids = $_GET['request_ids'];
       $request_ids = explode(",", $request_ids);
       foreach($request_ids as $request_id)
            {
                 $request_object = $facebook->api($request_id);
                 if(isset($request_object['data'])) $req_data = $request_object['data'];//you can now use the sent $req_data your way
                 $full_request_id = $request_id."_".$current_user_fbid;
                 $facebook->api("$full_request_id","DELETE");
            }
   }

Upvotes: 2

Vishwesh Shetty
Vishwesh Shetty

Reputation: 727

I assume you would be using a Database. When a user invites a friend the response of the request sent would contain response.request and response.to. Store this request_id alongwith user and users friend id (invited friends).

function inviteuser(){
    FB.ui({
        method: 'apprequests',
        message: "Apllications message goes here",
        exclude_ids: [1, 2, 3],
        filters:['app_non_users'],
        data: "optional additional data you may pass for tracking"
    }, function (response) {
        if (response && response.to) {
        //callback function, will be called after user invites his friend, response object will contain list of all users invited
        //save response.to and response.request in database
        }
    });
}

When user accepts an invitation i.e. comes to your application canvas page by clicking on app request notification, Facebook sends comma separated ids in "request_ids" parameter. You can get this request ids and compare with your database to get required information.

Upvotes: 1

Related Questions