dongshushen4392 2012-05-26 19:04
浏览 133
已采纳

Facebook获得正确的访问令牌

What is the difference between the long and short access tokens?

for example i am trying to get mutual friends using the following:

https://graph.facebook.com/$uid1/mutualfriends/$uid2?access_token=$token

and getting the access toke using the following function:

function getAccessToken(){
    $url ='https://graph.facebook.com/oauth/access_token?client_id='.FB_APP_ID.'&client_secret='.FB_SECRET_ID.'&grant_type=client_credentials';
    $info = file_get_contents($url);
    $clean = clean_up_data($info);
    return($clean);

}

but this does not work as the token is not valid, although if i used the access token found in Graph API Explorer it works but this token changes to much.

So how would you go about getting the valid token to allow access to mutual friends?

  • 写回答

1条回答 默认 最新

  • doucheng9634 2012-05-26 19:55
    关注

    The token you get by using the code in your question is an app token and it can not be used to get friends of the user. The app token does not expire unlike the user token.

    User token can be short or long lived, based on how you obtained them. The short lived expire within a few hours, but the longed lived tokens expire only after 60 days.

    Short lived tokens are produced for the logged in user with the javascript sdk and the client side authentication flow and can be extended to long lived tokens using this new endpoint. The server side flow also produces long lived tokens.

    Once the app gets a user access token it cam them query for data on the behalf of the logged in user. You can check that with the explorer tool by selecting the application on the top right and then clicking the "Get Access Token" button, after allowing the app and permissions you'll see that the "Access Token" field has the access token and you can start making api requests.

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

报告相同问题?

悬赏问题

  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档