Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating facebook apprequests

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.

like image 854
slash197 Avatar asked Jan 18 '23 19:01

slash197


2 Answers

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

  • user initiated (with the request dialog )
  • app generated (with the Graph API)

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.

like image 122
Lix Avatar answered Feb 07 '23 14:02

Lix


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

  1. Sending an email to a user when someone posts on their wall

  2. Sending an event invite to a user

  3. Sending an app invite to a user

  4. Writing on a users wall when something happens like 'XYZ shared a file with you'.

To answer

  1. You need email and read_stream permissions of the user. Monitor his wall using the RealTime Updates and then email him using your server SMTP.

  2. See http://developers.facebook.com/docs/reference/api/event/#invited on how to create an event invite

  3. As @Lix pointed out, see https://developers.facebook.com/docs/channels/#requests

  4. You should accomplish this using the new Open Graph object/actions. See this example: https://developers.facebook.com/docs/beta/opengraph/tutorial/

like image 22
DMCS Avatar answered Feb 07 '23 13:02

DMCS