Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Couldn't get you code to work either, it just reloaded. Seems $_REQUEST["signed_request"] was never set.</p> <p>But I got it to work with the code from <a href="http://developers.facebook.com/docs/authentication/" rel="nofollow noreferrer">http://developers.facebook.com/docs/authentication/</a></p> <pre><code> &lt;?php $app_id = "your app id"; $app_secret = "your app secret"; $my_url = "your app url"; session_start(); $code = $_REQUEST["code"]; if(empty($code)) { $_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&amp;redirect_uri=" . urlencode($my_url) . "&amp;state=" . $_SESSION['state']; echo("&lt;script&gt; top.location.href='" . $dialog_url . "'&lt;/script&gt;"); } if($_REQUEST['state'] == $_SESSION['state']) { $token_url = "https://graph.facebook.com/oauth/access_token?" . "client_id=" . $app_id . "&amp;redirect_uri=" . urlencode($my_url) . "&amp;client_secret=" . $app_secret . "&amp;code=" . $code; $response = file_get_contents($token_url); $params = null; parse_str($response, $params); $graph_url = "https://graph.facebook.com/me?access_token=" . $params['access_token']; $user = json_decode(file_get_contents($graph_url)); echo("Hello " . $user-&gt;name); } else { echo("The state does not match. You may be a victim of CSRF."); } </code></pre> <p>That said, I would recommend you to use the Facebook PHP SDK, <a href="http://developers.facebook.com/docs/reference/php/" rel="nofollow noreferrer">http://developers.facebook.com/docs/reference/php/</a> that makes programming facebook apps easier.</p> <h1>EDIT: using the PHP SDK</h1> <p>To authenticate with the PHP SDK, you would do something like the following:</p> <pre><code>// update this to where you've stored the facebook PHP SDK require '../src/facebook.php'; $facebook = new Facebook(array( 'appId' =&gt; 'your app id', 'secret' =&gt; 'your app secret', )); $user = $facebook-&gt;getUser(); if ($user) { print "You've logged in!"; } else { echo("&lt;script&gt; top.location.href='" . $facebook-&gt;getLoginUrl() . "'&lt;/script&gt;"); } </code></pre> <h1>EDIT: headers</h1> <p>Also, try setting this in the first lines of you code:</p> <pre><code>ini_set('session.use_trans_sid', 1); header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'); </code></pre> <p>This helped me when the fb session was lost sometimes in an app. Found that in this post: <a href="https://stackoverflow.com/questions/6468103/how-to-properly-handle-session-and-access-token-with-facebook-php-sdk-3-0">How to properly handle session and access token with Facebook PHP SDK 3.0?</a></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. 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