Whenever I try to login a prompt opens asking for the basic permissions, after that its being redirected to my redirect_uri with an URL
=">http://localhost/demo/?code=AQDwzia3Wx1BktixF59jVHbm0ViGVJm8Xhb2tNZDyYreZh0KoSJhrSsJ8Aa2KX3gocwR0XNQjQz7ZlBh26_nBi-3iOMByhVO2cxwJ8maC4IHxBacfqXjzqIyBaZQbWKUUxPI6VBrqBgFXQasj7PEtmug7lt93dK4fmMC2A4i2dUYU-gSvzn0f0ZdB3eT_aSvgR1KoLCmQgLh3xix4H05QR6LCP9nLtQC4l9rMJW83kS0PNmWq0COZYvGfuX1R7519Fn3iXRB9F0MTsK1KQ_ulpK84PUCkuMu8et88Lln0ZwuzaPo0oERelkPWYnrrTKa-5w&state=ed66ea618d8076d9e72c15d9a65a6312#=
Even though facebook->getUser() returns 0
Here is my code
<?php
require_once('php-sdk/facebook.php');
$facebook = new Facebook (array(
'appId' => '1234',
'secret' => '12313',
'cookie' => true
));
?>
<html>
<head> <title> Warming Up with FB API </title> </head>
<body> <h1> Hello World </h1> </body>
</html>
<?php
$loginUrl = $facebook->getLoginUrl(array (
'display' => 'popup',
'redirect_uri' => 'http://localhost/demo'
));
$user = $facebook->getUser();
//echo $user. '</br>';
if ($user) {
echo '<em>User Id: </em> '.$user;
} else {
$loginUrl = $facebook->getLoginUrl(array (
'display' => 'popup',
'redirect_uri' => 'http://localhost/demo'
));
echo '<a href = "'.$loginUrl.'">Login Here </a> ';
}
?>
I know its a very trivial question but I am kinda stuck at this and unable to proceed further. Kindly suggest what to do.
*UPDATE*
Leaving the App Domain empty solved my problem.
It might be Worked using
Change this
to
And see if this works !!
After several hours, the solution for me was (Let's say my site is http://www.site123.com):
Settings @ https://developers.facebook.com
PHP Code - fb_config.php
Important Note Also: I had some issues with Firefox $facebook->getUser() was 0 even my code was working on Chrome. But after cleaning Firefox cache, it worked nicely!
Hope it helps.
If User is logged in and still getting $user = 0 I faced this issue on different occasions but SDK issue is not happening to everyone. So I'm not sure what goes wrong here. But I dig in to it little bit and found solution as mentioned below.
SOLUTION : This worked for me after trying for many solutions for this issue.
In base_facebook.php file, find the makeRequest() method and check for following Line.
Immediately following it, add this line
More details can be found here - http://net.tutsplus.com/tutorials/php/how-to-authenticate-your-users-with-facebook-connect/
if someone is still banging their head over this here is what is wrong now. I was hired to fix this mess!
Check App domain in fb panel , must match with the domain where your app is.
edit base_facebook.php find:
public function getAccessToken() {
}
to::
find the line:
replace it with:
commenting the original and adding json_decode
thats it!