Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>";
}
?>
like image 262
user830713 Avatar asked Dec 20 '11 08:12

user830713


1 Answers

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/

like image 175
xero Avatar answered Nov 12 '22 23:11

xero