简体   繁体   中英

Facebook PHP SDK 3.0 - OAuthException: An active access token must be used to query information about the current user

I can't seem to fix this problem! Even after directing the user to getLoginUrl(), I can't seem to get the user authorized.

I've tested this in two windows: Chrome's Incognito (private) browsing, and normal browsing.

Incognito works, but normal browsing fails with "OAuthException: An active access token must be used to query information about the current user", even after logging out first.

Here's the code:

<?php
require_once("facebook/facebook.php");

require_once("includes/config.php");

$config = array();
  $config['appId'] = 'sdfasdf';
  $config['secret'] = 'asdfasdf';
  $config['cookies'] = true; // optional

$facebook = new Facebook($config);

$uid = $facebook->getUser();

if($uid)
{
    try
    {
        $user_profile = $facebook->api("/me");
        echo "Welcome, " . $user_profile['name'] . "!";
    }
    catch(FacebookApiException $fae)
    {
        echo $fae->getMessage();
        echo "<a href=\"". $facebook->getLoginUrl()."\">Login.</a>";
        $uid = null;
    }
}
else
{
    echo "<a href=\"". $facebook->getLoginUrl()."\">Login.</a>";
}
?>

i know that suggesting a different library might not be what you want to hear, but i have used the hybrid auth lib on tons of projects w/o any problems.

http://hybridauth.sourceforge.net/

If you are still developing the app and the app is not in production, then deleting the app and creating a new one is the fastest way to fix this problem.

I was struggling with the same problem. Since I am still developing the app, I deleted the app from facebook and created a new app. Now am using the appId and secret of the new app and everything works like a charm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM