Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can extend your token the following way:</p> <p>Original scenario</p> <ul> <li>Your app requests permissions from the user</li> <li>You prompt user to log in / grant permissions</li> <li>You get user's token (short-lived one) and exchange via CURL or other means for a 60 day one using grant_type=fb_exchange_token</li> <li>You persist the token</li> </ul> <p>Now you have that token to do what you wish with it for up to 60 days. Up to, because user can change password, de-authorize app, etc and token would become invalid. What you can do to extend the token is EVERY TIME user comes to your page(s), you can check if they are logged in via javascript and if they are, make an ajax call to your server to extend existing token for 60 days from today. You can make as many calls as you want, only the first one is valid. Here's how I do it:</p> <ol> <li><p>On your page somewhere during load event, add something like:</p> <pre><code> FB.getLoginStatus(function (response) { if (response.status === 'connected') { $.ajax({ type: "POST", async: false, url: YOUR_URL, dataType: "text", data: {token : response.authResponse.accessToken } }); } }); //rest of jquery ajax call here </code></pre></li> </ol> <p>That will get a new client-side access token for the user and send it to the server</p> <ol> <li><p>Server can then take that token and exchange it for a 60 day one </p> <pre><code>$token_url = "https://graph.facebook.com/oauth/access_token?client_id=".FACEBOOK_CLIENT_ID."&amp;client_secret=".FACEBOOK_SECRET."&amp;grant_type=fb_exchange_token&amp;fb_exchange_token=".$token; $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($c, CURLOPT_URL, $token_url); $contents = curl_exec($c); $err = curl_getinfo($c,CURLINFO_HTTP_CODE); curl_close($c); $paramsfb = null; parse_str($contents, $paramsfb); </code></pre></li> </ol> <p>Reference:</p> <p><a href="https://developers.facebook.com/roadmap/offline-access-removal/" rel="nofollow">https://developers.facebook.com/roadmap/offline-access-removal/</a> </p> <p>That would only extend the token if the user comes back to your site within 60 days. If not, you will need to prompt for permissions again.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload