Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A good and easy way to deal with Facebook authentication is to implement the server side flow with the Facebook PHP SDK (<a href="https://github.com/facebook/php-sdk" rel="nofollow">see on github</a>). So you will have something like :</p> <pre><code>require "facebook.php"; $facebook = new Facebook(array( 'appId' =&gt; YOUR_APP_ID, 'secret' =&gt; YOUR_APP_SECRET, )); $user = $facebook-&gt;getUser(); </code></pre> <p>If the user is logged in, then <code>$user</code> is his Facebook ID. You then have to check if you have a valid access token by making an API call :</p> <ul> <li><p>If it does not raise any exception, then you have a valid access token</p></li> <li><p>If it does, then you have to re-authenticate the user.</p></li> </ul> <p>Here :</p> <pre><code>if ($user) { try { $facebook-&gt;api('/me'); } catch (FacebookApiException $e) { $user = null; } } </code></pre> <p>You need then to display the login or logout link :</p> <pre><code>&lt;?php if ($user): ?&gt; &lt;a href="&lt;?php echo $facebook-&gt;getLogoutUrl() ?&gt;"&gt;Logout of Facebook&lt;/a&gt; &lt;?php else: ?&gt; &lt;a href="&lt;?php echo $facebook-&gt;getLoginUrl() ?&gt;"&gt;Login with Facebook&lt;/a&gt; &lt;?php endif ?&gt; </code></pre> <p>When the user is logged in and you have a valid access token, you can make API calls to get data from Facebook :</p> <pre><code>$user_profile = $facebook-&gt;api('/me'); </code></pre> <p>You may want to check the <a href="https://github.com/facebook/php-sdk/blob/master/examples/example.php" rel="nofollow">example page of the Facebook PHP SDK</a> which is well documented.</p> <p>Hope that helps.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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