简体   繁体   English

Facebook Graph API getAccessToken()/访问令牌到期

[英]Facebook Graph API getAccessToken() / Access token expiration

I'm going to be writing a Facebook Graph script/application that will run as a cron. 我将要编写一个将作为cron运行的Facebook Graph脚本/应用程序。 I tried to do this before, but it said that the access token expired. 我以前尝试过这样做,但是它说访问令牌已过期。 I tried using getAccessToken() , but it told me that a valid access token had to be used to request information about the current user. 我尝试使用getAccessToken() ,但是它告诉我必须使用有效的访问令牌来请求有关当前用户的信息。 How can I automatically renew my access token so my cron job won't break? 如何自动续订访问令牌,以使我的Cron工作不会中断?

The normal access token expires in 2 hours, and the extended token lasts for 2 months. 普通访问令牌将在2小时后过期,扩展令牌将持续2个月。 For the extended token guide, go though this: How to extend access token validity since offline_access deprecation 对于扩展令牌指南,请仔细阅读以下内容: 自从offline_access弃用以来,如何扩展访问令牌的有效性

Now, the best thing you can do is to update regularly this extended token of the user when he log-in the app/website. 现在,您能做的最好的事情就是在用户登录应用程序/网站时定期更新该扩展令牌。 So, you can use this token in your cron job. 因此,您可以在cron作业中使用此令牌。 This will fail only when the user didn't visit your app for 2 months. 仅当用户两个月未访问您的应用程序时,此操作才会失败。

Did you verify expiry of your access token at below link? 您是否在下面的链接中验证了访问令牌的有效期?

https://developers.facebook.com/tools/debug https://developers.facebook.com/tools/debug

Moreover, you can get detailed answer by visiting similar question: 此外,您可以通过访问类似的问题来获得详细的答案:

How to renew/extend facebook access tokens with PHP? 如何使用PHP更新/扩展Facebook访问令牌?

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

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