Creating facebook apprequests

slash197 picture slash197 · Jan 14, 2012 · Viewed 11.6k times · Source

I'm trying to send a message from an app to a user when a specific event happens. Right now I have this code

$param = array(
   'message'      => 'XYZ shared a file with you',
   'data'         => 'additiona_string_data',
   'access_token' => $facebook->getAccessToken(),
);
$tmp = $facebook->api("/$uid/apprequests", "POST", $param);

but I always get Uncaught OAuthException: (#2) Failed to create any app request thrown

I don't know where is the problem.

Answer

Lix picture Lix · Jan 14, 2012

You should read the requests documentation.
In there is an explination about two different types of requests.

What you need is the app generated requests, that means you'll need the apps access token and not the users.

I assume that you are using the users access token because you did not include the initiation of the facebook object in your code sample and have probably verified the user already hence the getAccessToken() call will return the users access token and not the applications access token.