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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With