Question

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

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

The script is working fine, and when the user clicks on the the app icon(with the red notification), at the top right corner of the canvas, he gets redirected to ther app's index page(apps.facebook.com/MY-APP), which is also fine. My question is, what parameter should I add in my FB.api call so that the user gets redirected to my desired app url(eg: apps.facebook.com/MY-APP/show-article/?article_id=5) instead of the index url.

Was it helpful?

Solution

Requests always direct user to your application canvas.

Citing Requests documentation:

Requests are only available for Canvas apps, not websites, as accepting a request will direct the user to the Canvas Page URL of the app that sent the Request.

Possible solution will be addition of desired URL within Request data property and once user land on your Canvas URL with requests_ids passed in URL arguments, read those requests and decide based on data property where user should be redirected.

data
Optional, additional data you may pass for tracking. This will be stored as part of the request objects created. The maximum length is 255 characters.

Update:
To get the data assigned with application/user request fetch it from Graph API:

https://graph.facebook.com/<REQUEST_OBJECT_ID>_<USER_ID>?access_token=APP_ACCESS_TOKEN
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top