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 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建