Facebook 应用程序的访问令牌是否会过期?
这是与我的 Facebook 应用程序关联的访问令牌——从 https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=APP_ID&client_secret=APP_SECRET。我可以从 FB 获取一次并将其保存在某个地方以供将来使用,还是需要定期刷新?
This is the access token associated with my Facebook application -- the thing that comes back from https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=APP_ID&client_secret=APP_SECRET. Can I get this once from FB and save it away somewhere for future use, or do I need to refresh it on a regular basis?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
访问令牌工具 - Facebook 开发者
Access Token Tool - Facebook Developers
我不确定,但由于 文档 没有说明您得到返回访问令牌的过期时间,我想这是一个有根据的猜测,它不会过期。
但这为什么重要呢?应用程序身份验证过程比用户身份验证过程简单得多,因此只需将令牌保存在某处(数据库、内存),然后尝试 api 调用,如果失败,只需发出一个调用来获取新令牌,保存该令牌,然后继续通常。
I don't know for sure, but since the documentation does not state that you get back an expiration time for the access token, I guess that it's an educated guess that it does not expire.
But why does it matter? the application authentication process is much simpler than the one with users, so just save the token somewhere (db, memory) and then try an api call, if it fails just issue one call to obtain a new token, save that, and continue as usual.
如果您想要令牌来管理页面,可以通过
当您检查您获得的令牌时,请在调试器上检查它。您现在将看到“永不过期”。
文档位于 Facebook 开发人员 上,场景 5:页面访问令牌
If you want a token to manage a page, never-expiring token can be obtained by
When you check the token you've got, check it on Debugger. You will now see 'Expires Never'.
Documentation is on Facebook Developers ,Scenario 5: Page Access Tokens
我的应用程序访问令牌似乎在不到一个月的时间内没有发生变化。我不知道它是否会改变。为了好玩,我刚刚更改了我的应用程序秘密...
然后我的应用程序访问令牌立即更改,当我尝试使用旧的时,我得到了一个
消息正文出现 HTTP 400 错误...
{"error":{"message":"无效的 OAuth 访问令牌签名。","type":"OAuthException","code":190}}
我的建议是保存访问权限令牌并使用它。除非您收到上述消息,在这种情况下,请获取一个新的并使用它。我尚未检查的一件事是,如果用户访问令牌(您可能正在查询)已过期,您是否会得到相同的结果。
My app access token does not seem to have changed for just under a month. I do not know if it changes. For fun I just changed my app secret...
My app access token then immediately changed and when I try to use the old one I get a
HTTP 400 error with a message body...
{"error":{"message":"Invalid OAuth access token signature.","type":"OAuthException","code":190}}
My advice is save the access token and use it. Unless you get the message above in which case obtain a new one and use that. One thing that I have not checked yet is if you get the same result if the user access token (that you may be querying) has expired instead.
对于每个用户令牌(即您从链接中获得的令牌),都有一个到期日期。将这些令牌之一带到 https://developers.facebook.com/tools/debug 并进行调试它。您会发现它们通常会在 60 分钟左右过期。
要延长该用户令牌,请调用交换命令 (https://developers.facebook.com/docs/offline-access-deprecation/) 以使其成为 60 天的令牌。该用户令牌必须仍然有效(未过期)才能执行此操作。
For each and every user token (which is what you're getting from your link), there is an expiration date. Take one of those tokens to https://developers.facebook.com/tools/debug and debug it. You will see that generally they expire within 60 minutes or so.
To extend that user token, call the exchange command (https://developers.facebook.com/docs/offline-access-deprecation/) to get it to become a 60 day token. That user token has to be still valid (not expired) to do this.