1

I am trying to send app-generated request using either JS SDK or graph API but I am not successful and desperate. Issue is that when I am sending request to currently logged user, everything is ok, but when I try to send to different user (even this user already authorized my app) I receive OAuth exception "#2 User can't send this request: Unknown error", sometimes "Failed to send any app requests".

My app has Request 2.0 enabled and is authorized with publish_stream, read_stream and user_about_me permissions. Same error messages I described are shown even in Graph API explorer.

Exactly same issue is described here using JS SDK: Sending an App Generated Request with the JavaScript SDK

... and here using Graph API: Posting app generated apprequest to other facebook users in Java

Please help.

Edgar
  • 11
  • 3
  • how do you select the user to whom you want to send the request?, and the code that you are using? – bool.dev Oct 06 '11 at 09:11
  • Using JS SDK like this: FB.api( "/" + recipient + "/apprequests", "POST", { message: "Notification Message", data: "Notification data" }, function( response ) { console.log( response ); } ); – Edgar Oct 06 '11 at 10:49
  • possible duplicate of [Sending an App Generated Request with the JavaScript SDK](http://stackoverflow.com/questions/7496981/sending-an-app-generated-request-with-the-javascript-sdk) – genesis Oct 13 '11 at 17:49
  • @genesis: They are duplicates. – Alexcode Nov 28 '11 at 12:09

1 Answers1

0

If you want send a request to a user, you should POST to the Graph API '/user_id/apprequests' using an App Access Token (https://developers.facebook.com/docs/authentication/#applogin). This call is to design to be executed server-side as you don't want to share your App Access Token:

curl -F 'access_token=APP_ACCESS_TOKEN' \
-F 'message=From the app to the user.' \
https://graph.facebook.com/USER_ID/apprequests

The same can be achieve using the User Access Token from the recipient (USER_ID) only:

curl -F 'access_token=USER_ACCESS_TOKEN' \
-F 'message=From the app to the user.' \
https://graph.facebook.com/USER_ID/apprequests

In the JS SDK, if no Access Token field is added, the default Access Token will be of the logged in user. Knowing that, the above call which send the a request to the logged in user, will be:

FB.api('/me/apprequests', 'POST',  {message: 'From the app to the user.'});

The first call can also be done with the JS SDK, by adding the App Access Token in the parameters. However, this is a DO NOT USE case as you don't want to share your App Access token client-side.

Alexcode
  • 1,598
  • 7
  • 15