Before i state my problem i must say that i have visited all these SO 1 , SO 2 , SO 3 , SO 4 links and many others and none of them solving my query
with facebook-php-sdk i am trying to login a user. on first few occasions it was working perfectly fine (2 to 3 days ago.). Today when i started again working with my project its not working any more.whenever i am trying to login a user $facebook->getUser(); throwing Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user.
i have also noted that getuser()
is also returning 0` though few days back it was working fine.
MY CODE :: 0auth_provided_by_facebook.php
include_once $_SERVER['DOCUMENT_ROOT'].'dist/facebook-php-sdk/src/facebook.php';
$config = array(
'appId' => '***********',
'secret' => '*********',
'allowSignedRequest' => false, // optional but should be set to false for non-canvas apps
'cookie' => true,
'oauth' => true
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
if($user_id) {
try {
$user_profile = $facebook->api('/me','GET');
} catch(FacebookApiException $e) {
$login_url = $facebook->getLoginUrl(array(
scope'=>'email,user_location,user_photos,publish_actions,publish_stream,basic_info',
'redirect_uri' => 'http://localhost/dist/include/0auth_provided_by_facebook.php'
));
echo "EXCEPTION at place 1";
error_log($e->getType());
error_log($e->getMessage());
}
} else {
// No user, print a link for the user to login
//$login_url = $facebook->getLoginUrl();
$login_url = $facebook->getLoginUrl(array(
'scope' => 'email,user_location,user_photos,publish_actions,publish_stream,basic_info',
'redirect_uri' => 'http://localhost/dist/include/0auth_provided_by_facebook.php'
));
echo "Exception at place 2";
}
It is always throwing the error mentioned above and and printing Exception at place 2. which means $user_id = $facebook->getUser();if($user_id)
returnin false...
EDIT :
as mentioned in the now i have used
getAccessToken
and setAccessToken
after $user_id = $facebook->getUser();
now my code
include_once $_SERVER['DOCUMENT_ROOT'].'dist/facebook-php-sdk/src/facebook.php';
$config = array(
'appId' => '234360450080751',
'secret' => '38189c40cec699c7c0deee2377a2c0a2',
'allowSignedRequest' => false, // optional but should be set to false for non-canvas apps
'cookie' => true,
'oauth' => true
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
$access_token = $facebook->getAccessToken();
$facebook->setAccessToken($access_token);
//....REST ARE SAME
How to solve it these two problem ??? what is the reason ??
i am giving more details it may help you to answer my query.
my fb app settings :
- APP DOMAIN : kept it blank according to the comments
- SITE URL :
http://localhost/dist/include/0auth_provided_by_facebook.php
- Native or desktop app? Disabled (i tried by enabling but no help)
- Deauthorize Callback URL :
http://localhost:80/dist/
- Valid OAuth redirect URIs
http://localhost/dist/include/0auth_provided_by_facebook.php
- Stream post URL security : ENABLED
- Normalize all publish scopes to 'publish_actions :' Enabled