简体   繁体   English

如何获取Facebook用户访问令牌

[英]How to get Facebook user access token

After hours of Googling and research, I cant find out how to get the facebook user access token. 经过数小时的谷歌搜索和研究,我无法找到如何获取Facebook用户访问令牌。 I have an app which wants to access my posts. 我有一个想要访问我帖子的应用程序。 I have used facebook php sdk and Graph Api call , but in both the cases what I got is an app access token. 我使用了facebook php sdkGraph Api call ,但是在两种情况下,我得到的都是应用程序访问令牌。 The error when I used this token to get the posts is 我使用此令牌获取帖子时的错误是

Uncaught OAuthException: A user access token is required to request this resource.

I found it needs user access token with the permissions. 我发现它需要具有权限的用户访问令牌。 Eventually I got a way to get the user access token. 最终,我有了一种获取用户访问令牌的方法。 I have used the Graph API Explorer to get a shot lived user access token and then I have extended it using expires parameter and my app is working well. 我使用了Graph API Explorer来获取实时的用户访问令牌,然后使用expires参数对其进行了扩展,并且我的应用程序运行良好。 I am still searching for a way to get the user access token by Graph API call or PHP SDK . 我仍在寻找一种通过Graph API调用或PHP SDK获取用户访问令牌的方法。

I want to get the user access token for my own Facebook account. 我想获取我自己的Facebook帐户的用户访问令牌。 Please help me. 请帮我。

Thanks 谢谢

If you follow the example given by the PHP SDK https://raw.github.com/facebook/facebook-php-sdk/master/examples/example.php then you should be able to understand how to login. 如果您遵循PHP SDK https://raw.github.com/facebook/facebook-php-sdk/master/examples/example.php给出的示例,那么您应该能够了解如何登录。

Also see the Getting Started version of the PHP SDK in developers.facebook.com https://developers.facebook.com/docs/php/gettingstarted/ 另请参阅developers.facebook.com https://developers.facebook.com/docs/php/gettingstarted/中的PHP SDK入门版本。

The gist of it is that the user logs in via the link provided from the getLoginUrl() method after which the user will go through an authentication flow similar to the flow you experienced when requesting an access token from the Graph API Explorer 其要点是用户通过getLoginUrl()方法提供的链接登录,此后,用户将通过身份验证流程,类似于您从Graph API Explorer请求访问令牌时经历的流程

授权流程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM