Getuser() method of Facebook PHP SDK always returns 0

血红的双手。 提交于 2020-01-25 08:50:09

问题


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:

  1. You didn't authenticated your application.
  2. You are running the app from localhost and provided the name in graph API as of your domain or something else.
  3. Your access token is expired.


来源:https://stackoverflow.com/questions/13599758/getuser-method-of-facebook-php-sdk-always-returns-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!