Create facebook apps

I am trying to send a message from an application to a user when a specific event occurs. I have this code right now

$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 do not know where the problem is.

+4
source share
3 answers

You should read the documentation for the requests.
It has an explanation about two different types of queries.

  • user started (with dialog box)
  • application generated (with Graph API )

What you need is an application generated by users , which means that you need an access token for applications, not users.

I assume that you are using the user access token because you did not include the initiation of the facebook object in your code sample and probably verified the user, so the call to getAccessToken() will return the user access token, not the application access token.

+8
source

I am a little confused that "I am trying to send a message from the application to the user when a specific event occurs. Now I have this code."

  • Sending email to a user when someone posts on the wall

  • Sending an invitation to user to user

  • Sending an application invitation to a user

  • Writing on the users wall when something happens, for example, "XYZ shared a file with you."

To reply

+1
source

You can get a Facebook access token through:

 https://graph.facebook.com/oauth/access_token?client_id=FB_APP_ID&client_secret=FB_APP_SECRET&grant_type=client_credentials 

Sample working code for sending an application request to a user using the PHP PHP SDK (add error handling, if necessary):

 $facebook = new Facebook(array( 'appId' => FB_APP_ID, 'secret' => FB_APP_SECRET, )); $token_url = "https://graph.facebook.com/oauth/access_token?" ."client_id=" . FB_APP_ID ."&client_secret=" . FB_APP_SECRET ."&grant_type=client_credentials"; $result = file_get_contents($token_url); $splt = explode('=', $result); $app_access_token =$splt[1]; $facebook->setAccessToken($app_access_token); $args = array( 'message' => 'MESSAGE_TEXT', ); $result = $facebook->api('/USER_ID/apprequests','POST', $args); 
0
source

Source: https://habr.com/ru/post/1390983/


All Articles