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.
The OAuth 2.0 standard, RFC 6749, defines the expires_in field as the number of seconds to expiration: expires_in: RECOMMENDED. The lifetime in seconds of the access token. For example, the value "3600" denotes that the access token will expire in one hour from the time the response was generated.
When a token has expired or has been revoked, it can no longer be used to authenticate Git and API requests. It is not possible to restore an expired or revoked token, you or the application will need to create a new token.
Access tokens can expire for many reasons, such as the user revoking an app, or if the authorization server expires all tokens when a user changes their password. If you make an API request and the token has expired already, you'll get back a response indicating as such.
For example, once an access token expires, the client application could prompt the user to log in again to get a new access token. Alternatively, the authorization server could issue a refresh token to the client application that lets it replace an expired access token with a new one.
It is the no of seconds before expiry time. i.e.
3994 / 60 / 60 =~ 1 hour
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):
scope=offline_access
At my project (http://www.nbusy.com/projects/communicator) I use something like the below to know of the token expiry time:
DateTime eprityTime = DateTime.Now.AddSeconds(3994);
and compare it with DateTime.Now and close the session when token expires.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With