Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Facebook应用程序未检索用户信息_Php_Facebook Graph Api - Fatal编程技术网

Php Facebook应用程序未检索用户信息

Php Facebook应用程序未检索用户信息,php,facebook-graph-api,Php,Facebook Graph Api,我刚刚用Facebook PHP SDK构建了一个应用程序并进行了设置。我正在测试它,虽然我从我的个人资料中获得了显示的图像,但请求的用户信息没有显示出来。这是结果的屏幕截图 下面是我上传到服务器的php代码。请注意,应用程序ID和密码已从此处删除 <?php require ('src/facebook.php'); $app_id = " "; //has been removed $secret = " "; //has been removed $app_url = "htt

我刚刚用Facebook PHP SDK构建了一个应用程序并进行了设置。我正在测试它,虽然我从我的个人资料中获得了显示的图像,但请求的用户信息没有显示出来。这是结果的屏幕截图

下面是我上传到服务器的php代码。请注意,应用程序ID和密码已从此处删除

<?php

require ('src/facebook.php');

$app_id = " "; //has been removed
$secret = " "; //has been removed
$app_url = "http://apps.facebook.com/instahomework/";

// Create our Application instance (replace this with your appId and secret). 
$facebook = new Facebook(array(
  'appId'  => $app_id,
  'secret' =>  $secret,
));

// Get User ID
$user = $facebook->getUser();

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

// Login or logout url will be needed depending on current user state.
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl(); 
}
// This call will always work since we are fetching public data.
$naitik = $facebook->api('/naitik');

?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
    <title>php-sdk example 1 - user login and authorisation</title>
    <style>
        body { font-family: Helvetica, Verdana, Arial, sans-serif; }
        a { text-decoration:none; }
        a:hover { text-decoration:underline; }
    </style>
</head>
<body>
<pre>
<?php print_r($_REQUEST); ?>
</pre>
    <?php if ($user) { ?>
        <h2>Welcome</h2>
        <img src="https://graph.facebook.com/<?php echo $user; ?>/picture"><br/>
        <a href="<?php echo $link; ?>"><?php echo $name; ?></a><br/>
        <br/>
        Gender : <?php echo $gender; ?><br/>
        Locale : <?php echo $locale; ?><br/>
        Username : <?php echo $username; ?><br/>
    <?php } else { ?>
        <strong><em>You have not granted this App permission to access your data. Redirecting to permissions request...</em></strong>
<?php } ?>
</body>
</html>

您应该将HTML代码替换为:

$user_profile = $facebook->api('/me');
并存储到
$user\u profile
数组中

另一种解决方法(但不推荐)是通过添加以下代码行,将facebook中的数据提取到全局变量范围中:

extract($user_profile);

您应该将HTML代码替换为:

$user_profile = $facebook->api('/me');
并存储到
$user\u profile
数组中

另一种解决方法(但不推荐)是通过添加以下代码行,将facebook中的数据提取到全局变量范围中:

extract($user_profile);

我看不到您设置
$gender
$locale
$username
的代码。它在哪里?@RaulPinto它在标签前面的第63-65行。感谢不是这样的,感谢
正在做的事情。检查Owens答案。我没有看到您正在设置的代码
$gender
$locale
$username
。它在哪里?@RaulPinto它在标签前面的第63-65行。感谢不是这样的,感谢
正在做的事情。检查欧文斯的答案。好的,谢谢你,这很有效。我会投票,但它不会让我投票,因为声誉低于15:/@JGallardo-检查答案是否正确,您的声誉将提高。好的,谢谢,这成功了。我会投票,但它不会让我投票,因为声誉低于15:/@JGallardo-检查答案是否正确,您的声誉将提高。