如何使用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?

duanlieshuang5330
duanlieshuang5330 好吧,我回答,我希望它有所帮助。如果您需要更多信息,请在答案中发表评论。
大约 6 年之前 回复
douyuan1049
douyuan1049 因此,制作由cron触发的命令并检查rss以获取新条目的整个逻辑没有问题,我只是不知道如何使用令牌进行图形调用,感谢任何帮助
大约 6 年之前 回复
doushi3454
doushi3454 我知道,但我必须从某个地方开始吧?我想要实现的目标是:用户接受应用程序的许可,从我们的网站选择rss-feed对他的评论,在后台我将检查是否有新的托管,如果是的话,我将其发布在他的墙上
大约 6 年之前 回复
douwang9650
douwang9650 你知道你不能预先填写消息参数,对吧?它始终必须是100%用户生成的。此外,“常规发布”听起来非常垃圾,用户应该能够授权每一个帖子-并且他必须为每个帖子输入他自己的消息。
大约 6 年之前 回复

1个回答

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

dtslobe4694
dtslobe4694 非常感谢,我使用appsecret_proof,它就像一个魅力!
大约 6 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐