如何解释收到访问令牌后的 oauth expires=4 位代码
在我的应用程序中,某些点击需要生成 Facebook 帖子。如果我没有访问令牌,我会弹出 Facebook 登录屏幕。
收到访问令牌后,我最后还会收到一个“expires=4 位数字”。
例如,expires=3994
这 4 位代码是什么意思?
访问令牌过期后的时间是否以秒为单位?
或者是访问令牌过期之前的刻度数。
我看到一些 facebook api 代码期望 12 位过期代码,但我只收到 4 位数字。
我需要知道访问令牌是否已过期的原因是我不希望我的帖子失败,并且希望在它已过期时弹出登录屏幕。
In my application, certain clicks need to generate facebook post. I popup the facebook login screen if I have no access token.
Upon receiving the access token I also receive a "expires=4 digit number" at the end.
e.g. expires=3994
What does that 4 digit code mean?
Is it time in seconds after which the access token will expire?
Or is it the number of ticks after which the access token will expire.
I have seen some facebook api code which expects 12 digit expires code but I am receiving only 4 digits.
The reason I need to know if the access token has expired is that I do not want my post to fail and would like to pop up the login screen if it has expired.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它是到期时间之前的秒数。即,
如果您看到更多数字(尤其是在画布访问链接上),它可能是一个 Unix 时间戳,您可以轻松地将其转换为秒。您也可以使用以下范围来获取未过期的令牌(但它将在授权弹出窗口中显示附加警告):
在我的项目中(http://www.nbusy.com/projects/communicator)我使用类似下面的内容来了解令牌到期时间:
并将其与 DateTime.Now 进行比较,并在以下时间关闭会话令牌过期。
It is the no of seconds before expiry time. i.e.
If you see more digits (especially on canvas access link), it is probably a Unix time-stamp which you can convert to seconds easily. Also you can use below scope to get a non expiring token (but it will display an additional warning with the authorization popup window):
At my project (http://www.nbusy.com/projects/communicator) I use something like the below to know of the token expiry time:
and compare it with DateTime.Now and close the session when token expires.
您最初在signed_request 中从Facebook 收到的令牌将在2 小时或7200000 毫秒或7200 秒后过期。如果您使用以下请求延长令牌,您将收到 5184000 秒的新过期时间,该时间转换为 60 天。
有关此答案的更多信息,请点击此处...facebook 访问令牌的到期时间
The token you receive initially from Facebook in the signed_request expires in 2 hours or 7200000 milliseconds or 7200 seconds. If you extend the token with the below request you will receive a new expire time of 5184000 seconds which converts to 60 days.
more on this answer here...Expiry Time of facebook access token