2

I want to send a request with the facebook app-graph.. sometimes successfully but sometimes failed with return value:

{
   "error": {
      "message": "(#2) Failed to create any app request",
      "type": "OAuthException",
      "code": 2
   }
}

please help me .. why did it happen?hehe

Fendi Tri Cahyono
  • 682
  • 1
  • 10
  • 20

1 Answers1

2

You need to send the app-to-user request using the application access_token. For example:

$param = array(
   'message'      => 'Check out the latest update',
   'data'         => 'some_data_string',
   'access_token' => 'app_id|app_secret',
);
$tmp = $facebook->api("/[user_id]/apprequests", "POST", $param);

EDIT:

See the facebook documentation for generating an app access_token. The documentation states:

There is another method to make calls to the Graph API that doesn't require using a generated app token. You can just pass your app id and app secret as the access_token parameter when you make a call:

https://graph.facebook.com/endpoint?key=value&access_token=app_id|app_secret

Niraj Shah
  • 15,087
  • 3
  • 41
  • 60
  • The value for access_token is not 'app_id|app_secret'. The actual access token must be obtained from Facebook. See: http://stackoverflow.com/questions/15405293 – Nick Oct 01 '13 at 14:00
  • Using `app_id|app_secret` works too. Try using the Access Token tool to check: https://developers.facebook.com/tools/debug/accesstoken. It's easier to do this, than making an additional API call. The facebook documentation also points this out: https://developers.facebook.com/docs/facebook-login/access-tokens/. `There is another method to make calls to the Graph API that doesn't require using a generated app token. You can just pass your app id and app secret as the access_token parameter when you make a call`. Get your facts right before down-voting. – Niraj Shah Oct 02 '13 at 09:52