Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess token on facebook is invalid - even after making it
    primarykey
    data
    text
    <p>I'm writing a facebook application in PHP with the facebook SDK.<br/> The important parts in my code are:<br/></p> <pre><code> $facebook = new Facebook(array( 'appId' =&gt; $ApplicationID, 'secret' =&gt; $ApplicationSecret, 'cookie' =&gt; true, // enable optional cookie support )); $user = $facebook-&gt;getUser(); $post = $facebook-&gt;api('/' . $user . '/feed', 'post', array( stuff )); $_SESSION['finish'] = false; $_SESSION['inside'] = 'yes'; $_SESSION['uid'] = $user; $token = $facebook-&gt;getAccessToken(); echo 'Access token: ' .$token; $_SESSION['friends'] = $facebook-&gt;api('/me/friends?access_token'.$token); </code></pre> <p>You can see I am <code>echo</code>ing the access token.<br/> At first, I haven't added the <code>access_token</code> into the query - I just added it for checking.<br/> The problem is that the last like (with the <code>/me/friends/</code>) throws an exception:</p> <pre><code>OAuthException: An active access token must be used to query information about the current user. </code></pre> <p>Although I did a login, and the <code>feed post</code> <em>did</em> work (I checked at my wall, it's there). Then, my <code>try catch</code> block handles the exception by redirecting to the login link, this way:</p> <pre><code>catch(Exception $e) { $login_url_params = array( 'scope' =&gt; 'stuff', 'fbconnect' =&gt; 1, 'redirect_uri' =&gt; $ApplicationURL ); $login_url = $facebook-&gt;getLoginUrl($login_url_params); //redirect to the login URL on facebook echo ("EXCPETION! " . $e . "&lt;script&gt; top.location.href='" . $login_url . "'&lt;/script&gt;"); exit(); } </code></pre> <p>The code writing the exception is obviously only for debugging purposes.<br/> Well, the first time I run the application a similar code is executed by a <code>if(!$user)</code> condition. Then it asks for my permission and I give it. Then, again, it says the access token is invalid (but does post to my wall).<br/> Please note that I've compared the access_tokens, and even after removing the application and doing it all again - it stayed the same.<br/><br/></p> <p>This is very awkward behavior and I fail to understand it. May anyone please shred some light on this? <br/> Edit: For some weird reason, the token doesn't change even after going to a different user. But the post on the wall is still made... (And the exception thrown when accessing the friends list)</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.
 

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