john Smith
john Smith

Reputation: 17926

How to use facebook access_token

I´m building a facebook app with php, everything works perfect, I do successful dialog auth I have the short_live token I generate the long_live_token and save it to some directory

what I want to do is that in canvas app the user selects some stuff and activates a mechanism that regularly posts stuff, this is why I save the token.

but what can I do with it?!

I find a lot about generating the access_token but nothing about how to use it!? Where can I add it as parameter? What is the key?

example:

I´m using facebook sdk for php for post sth. to a wall like

$msg_body = array(
    'message' => "wassup yo"
);
$facebook->api($uri, 'post', $msg_body );

but this only works if

  $facebook->getUser();

is returning a user

how can I use my stored access_token to do the same?

Upvotes: 0

Views: 54

Answers (1)

andyrandy
andyrandy

Reputation: 74014

I believe there is a function called "setAccessToken" in the Facebook PHP SDK. You would just need to set it with that function and it gets added to every call automatically.

Manual way:

$params = array(
    'message' => 'wassup yo',
    'access_token' => '[your-token]'
);
$facebook->api($uri, 'post', $params);

You could also do this with CURL, this would be an example URL;

$url = 'https://graph.facebook.com/' . $userId .
    '/feed' .
    '&access_token=' . $accessToken .
    '&message=' . $userMessage;

Basically you just add the Access Token as a parameter like the message.

Just make sure you are using secure calls, see this article for an example of using CURL with the Facebook API and usage of "appsecrect_proof": http://www.devils-heaven.com/extended-page-access-tokens-curl/

IMPORTANT: Be sure that the message parameter is always 100% user generated without any prefilling (see Platform Policy) and keep in mind that you need to go through a review process with pulish_actions to make it available for other Users: https://developers.facebook.com/docs/apps/changelog

Upvotes: 1

Related Questions