Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With the Facebook PHP SDK v3 (<a href="https://github.com/facebook/php-sdk" rel="noreferrer">see on github</a>), it is pretty simple to ask and use a user offline access token. Here is how you do that.</p> <h1>Get the offline access token</h1> <p>First you check if the user is logged in or not :</p> <pre><code>require "facebook.php"; $facebook = new Facebook(array( 'appId' =&gt; YOUR_APP_ID, 'secret' =&gt; YOUR_APP_SECRET, )); $user = $facebook-&gt;getUser(); if ($user) { try { $user_profile = $facebook-&gt;api('/me'); } catch (FacebookApiException $e) { $user = null; } } </code></pre> <p>If he is not, you generate the "Login with Facebook" URL asking for the <code>offline_access</code> permission :</p> <pre><code>if (!$user) { $args['scope'] = 'offline_access'; $loginUrl = $facebook-&gt;getLoginUrl($args); } </code></pre> <p>And then display the link in your template :</p> <pre><code>&lt;?php if (!$user): ?&gt; &lt;a href="&lt;?php echo $loginUrl ?&gt;"&gt;Login with Facebook&lt;/a&gt; &lt;?php endif ?&gt; </code></pre> <p>Then, when the user is logged in, you can retrieve the offline access token and store it. To get it, call :</p> <pre><code>if ($user) { $token = $facebook-&gt;getAccessToken(); // store token } </code></pre> <h1>Use the offline access token</h1> <p>To use the offline access token when the user is not logged in :</p> <pre><code>require "facebook.php"; $facebook = new Facebook(array( 'appId' =&gt; YOUR_APP_ID, 'secret' =&gt; YOUR_APP_SECRET, )); $facebook-&gt;setAccessToken("..."); </code></pre> <p>And now you can make API calls for this user :</p> <pre><code>$user_profile = $facebook-&gt;api('/me'); </code></pre> <p>Hope that helps !</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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