facebookfacebook-javascript-sdkfacebook-appsfacebook-app-requestsfacebook-requests

How to get the data param in an app generated request for a facebook user


I am sending an app generated request to a user(already authorized the app) by calling the below function

 function send_app_request(){
   FB.api( "/" + '<USER-ID>' + "/apprequests", "POST", {
     message: "Custom Request for you!",
     data: "<REDIRECT-APP-URL>",
     access_token: "<APP-ACCESS-TOKEN>"
   }, function(response) {
     console.log(response);
   });
 }

When a user clicks on the pop-up that appears beneath the app icon(with a red number) at the top right corner of the canvas, he gets redirected to the index page of the canvas with 'request_ids' as one of the parameters. How do I get/decode the 'data' parameter(contains a url) which i passed during the FB.api call(in the function above), so that I can redirect the user to a specific location(url) in my application.

I have seen this functionality in many applications, and I am "unable" to figure out how they are able to redirect the users to a specific location in their app, instead of the index page when the user clicks on the pop up.


Solution

  • The data is specific for that request you send to the user.

    When the user clicks the requests and gets to your page (with the "request_ids" parameter) you should then get the data for the requests.

    The url to get the requests from:

    https://graph.facebook.com/USER_ID/apprequests

    You will get a list of the requests and the data for each one (if such was sent). You then need to delete the request for the user by issuing a request to:

    https://graph.facebook.com/REQUEST_ID?method=delete

    You can find a php example here: Upgrade to Requests 2.0