Facebook PHP SDK的Getuser()方法始终返回0 [英] Getuser() method of Facebook PHP SDK always returns 0

查看:52
本文介绍了Facebook PHP SDK的Getuser()方法始终返回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:

  1. 您未对您的应用程序进行身份验证.
  2. 您正在从本地主机运行该应用程序,并在域或其他域中提供了图API的名称.
  3. 您的访问令牌已过期.

这篇关于Facebook PHP SDK的Getuser()方法始终返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆