Facebook PHP SDK的Getuser()方法始终返回0 [英] Getuser() method of Facebook PHP SDK always returns 0
问题描述
问题:我无法从Facebook的getuser()方法获取用户ID.
Problem: I am not able to get user id from Facebook's getuser() method.
说明:我创建了一个Facebook应用.保存更改后,我将站点URL设置为" http://localhost:8088/fb/".现在,我想获取用户ID,以便可以在Facebook上访问用户的信息.
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.
下面是我的代码:
<?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>
登录Facebook后,我得到的用户ID等于0.我需要执行任何设置吗?我已经搜索了许多解决方案,但是没有任何效果.如何获取用户ID?
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?
推荐答案
我对PHP不太了解,但原因可能是其中之一:
I don't know much about PHP but the reason might be one of these:
- 您未对您的应用程序进行身份验证.
- 您正在从本地主机运行该应用程序,并在域或其他域中提供了图API的名称.
- 您的访问令牌已过期.
这篇关于Facebook PHP SDK的Getuser()方法始终返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!