Note that there are some explanatory texts on larger screens.

plurals
  1. POFacebook app: OAuthException: An active access token must be used
    primarykey
    data
    text
    <p>i am having the next problem migrating my old facebook app to Oauth 2.0:</p> <p>when i try to read the user profile (in php code) i get the error: "<b>OAuthException: An active access token must be used to query information about the current user.</b>"</p> <p>The application makes the login operation via javascript and then it redirects to a page where from php i get the user profile.</p> <p>The javascript code:</p> <pre><code>&lt;script type="text/javascript"&gt; window.fbAsyncInit = function() { FB.init({ appId : '&lt;?php echo $facebook-&gt;getAppId() ?&gt;', cookie : true, // enable cookies to allow the server to access the session xfbml : true, // parse XFBML oauth : true // enable oauth }); // whenever the user logs in, we refresh the page FB.Event.subscribe('auth.login', function(response) { window.location="index.php"; }); }; (function() { var e = document.createElement('script'); e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; e.async = true; document.getElementById('fb-root').appendChild(e); }()); function login () { FB.login(function(response) { if (response.authResponse) { //console.log('Welcome! Fetching your information.... '); FB.api('/me', function(response) { //alert('Good to see you, ' + response.name + '.'); var url="./code.php"; window.location=url; }); } else { alert("Debes de identificarte y aceptar las condiciones para obtener el descuento"); } }, {scope: 'email'}); }; &lt;/script&gt; </code></pre> <p>The php part (in code.php):</p> <pre><code>require 'facebook-php-sdk/src/facebook.php'; // Create our Application instance (replace this with your appId and secret). $facebook = new Facebook(array( 'appId' =&gt; 'xxxxxxxxxxxxxxxxx', 'secret' =&gt; 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' )); $user = $facebook-&gt;getUser(); if ($user) { try { // Proceed knowing you have a logged in user who's authenticated. $me = $facebook-&gt;api('/me'); ..... </code></pre> <p>I have read different posts and tried things like getting the access_token from the javascript login response or from the cookie and then make the call to api('me/?access_token=...), but it didn´t work.</p> <p>Edit: Thanks a lot to everyone, it's working now!!</p> <p>Thanks</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.
 

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