Reputation: 12140
I use this code to get a valid token for 60 days
// Set Extended Access Token
$facebook->setExtendedAccessToken();
//get session
$session = $facebook->getAccessToken();
then i store it in the database and use it to post on the user's wall(*publish_stream* permission). However is there any way to renew the token, my user is unlikely to open the app in these 60 days (building a reminder app).
Please provide working code or how to for dummies
Upvotes: 2
Views: 722
Reputation: 22882
There's no way you can extend a token more than 60 days or renew it without user interaction.
But, if your user by any chance goes to your app during the 60 days, the token will be renewed automatically and it'll get another 60 days of lifetime.
Expiration and Extending Tokens
Facebook's official SDKs manage the lifetime of tokens for you. When using iOS, Android or our JavaScript SDK, the SDK will handle making sure that tokens are refreshed before they expire.
Native mobile applications using Facebook's SDKs will get long-lived access tokens, good for about 60 days. These tokens will be refreshed once per day when the person using your app makes a request to Facebook's servers. If no requests are made, the token will expire after about 60 days and the person will have to go through the login flow again to get a new token.
Access tokens on the web often have a lifetime of about two hours, but will automatically be refreshed when required. If you want to use access tokens for longer-lived web apps, especially server side, you need to generate a long-lived token. A long-lived token generally lasts about 60 days.
Also on the docs they say you shouldn't depend on these lifetimes, since users can revoke permissions, change his password (changing password will revoke every token for every app the user has installed)
User access tokens come in two forms: short-lived tokens and long-lived tokens. Short-lived tokens usually have a lifetime of about an hour or two, while long-lived tokens usually have a lifetime of about 60 days. You should not depend on these lifetimes remaining the same - the lifetime may change without warning or expire early.
All this info I quoted is here https://developers.facebook.com/docs/facebook-login/access-tokens/
Upvotes: 2
Reputation: 169
Unfortunately, The facebook does not provide any method for refreshing access token without user interference. The user must re-login the app to catch a fresh token, In this case the only benefit you get is that you catch fresh token without authorized dialog.
Upvotes: 2