doulingna9420 2014-08-20 21:17
浏览 105
已采纳

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

  • 写回答

1条回答

  • douji5397 2014-08-21 08:43
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写uniapp时遇到的问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流