Reputation: 155
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>";
}
?>
Upvotes: 7
Views: 2935
Reputation: 4319
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/
Upvotes: 1
Reputation: 795
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.
Upvotes: 0