Before i say something i want to say that i GOOGLEd a lot and there were lots of pages found(including many of so's question) with varieties of solutions ... but i have tried each of them one by one but unfortunately none of them worked for me
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() is returning 0
.Buts 3 days back it was working.
i have used the code given here :: developers.facebook.com and yes i have made some changes those are given with the full code below
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 '<a href="' . $login_url .'"> PLEASE CLICK HERE </a>';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
$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 '<a href="' . $login_url .'"> PLEASE CLICK HERE </a>';
}
OUTPUT : getUser() is always returning 0.
how my login process works described below :
after clicking on <a href="login_fb">Login using fb </a>
control goes to my localhost/dist/index.php
now my index.php include
the above wriiten code which is in different directory localhost/dist/include/0auth_provided_by_facebook.php
from this file i handle everything. on successful and failure of login facebook returns value here.and then on successful login user is again redirected to home
Now here is he full list of my app setting which i enabled or disabled or changed
1. App Domains : blank(according to the answer)
2. Site URL : `http://localhost/dist/include/0auth_provided_by_facebook.php?`
3. Native or desktop app? Disabled
4. Deauthorize Callback URL : `http://localhost/dist/include/0auth_provided_by_facebook.php?`
5. Social Discovery : enabled
6. Client OAuth Login : enabled
7. Embedded browser OAuth Login :enabled
8. App Secret Proof for Server API calls :enabled
9. Require 2-factor reauthorization : disabled
10. Valid OAuth redirect URIs :`http://localhost/dist/include/0auth_provided_by_facebook.php?` (according to the suggesion given in the answer)
11. Stream post URL security : enabled
these were the details. $user_id = $facebook-> getUser();
is always returning 0
in all condition. how can i solve it?
for more info .. thhough i dont know it will help you not...i was going through my base_facebook.php and i found that it is returning zero because of
if(signed_request)
is always false.