问题
Problem: I am not able to get user id from Facebook's getuser() method.
Description: I have created a Facebook app. I have given site URL as "http://localhost:8088/fb/" After saving the changes. Now I want to get user id so that I can access user's information on Facebook.
Below is my code:
<?php
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxx',
));
$user = $facebook->getUser();
echo $user;
if($user)
{
$logoutUrl = $facebook->getLogoutUrl();
}
else
{
$logoutUrl=$facebook->getLoginUrl();
}
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>php-sdk</title>
</head>
<body>
<?php if($user )
{
?>
<a href="<?php echo $logoutUrl; ?>">Logout</a>
<?php
}
else
{
?>
<a href="<?php echo $loginUrl; ?>">Login</a>
<?php
}
?>
</body>
</html>
After login to Facebook, I am getting user id equals to 0. Are there any settings that I need to perform? I have searched for many solutions but nothing works. How can I get the user id?
回答1:
I don't know much about PHP but the reason might be one of these:
- You didn't authenticated your application.
- You are running the app from localhost and provided the name in graph API as of your domain or something else.
- Your access token is expired.
来源:https://stackoverflow.com/questions/13599758/getuser-method-of-facebook-php-sdk-always-returns-0