0

这是不起作用的代码。我想显示当前用户也使用我的应用程序的朋友的列表。我可以通过在浏览器中键入变量 $url 并将访问令牌变量替换为页面上打印的访问令牌来手动获取 JSON 文件。出于安全原因,我删除了一些细节。

<?php
require 'fb/facebook.php';

$fbconfig['appUrl'] = "REMOVED_FOR_SECURITY"; 

// Create An instance of our Facebook Application.
$facebook = new Facebook(array(
  'appId'  => 'REMOVED_FOR_SECURITY',
  'secret' => 'REMOVED_FOR_SECURITY',
  'cookies' => 'true',
));

// Get the app User ID
$user = $facebook->getUser();
$access_token = $facebook->getAccessToken();

if ($user) {
    try {
        // If the user has been authenticated then proceed
        $user_profile = $facebook->api('/me');
    } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}

// If the user is authenticated then generate the variable for the logout URL
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();

?>
<html>
<head>
<title>Friend's JSON</title>
</head>
<body>
<?php
echo $user_profile['name'] . " is connected.";
echo "<br />Access token: " . $access_token;

$url = "https://graph.facebook.com/fql?q=SELECT name, uid FROM user WHERE is_app_user=REMOVED_FOR_SECURITY and uid IN (SELECT uid2 FROM friend WHERE uid1 = me())&access_token=" . $access_token;
$json = file_get_contents($url,0,null,null);
$array = json_decode($json, true);
echo $array['data']['name'];
echo $array['data']['uid'];
?>
</body>
</html>
<?php  
} else {
  $loginUrl = $facebook->getLoginUrl(array('redirect_uri' => $fbconfig['appUrl']));
  print "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
}
?>

这两行就是显示的全部内容:

echo $user_profile['name'] . " is connected.";
echo "<br />Access token: " . $access_token;

为什么你认为它不起作用?任何帮助,将不胜感激。提前致谢。

4

1 回答 1

0

这是我用来列出使用该应用程序的用户朋友的代码:

$facebook->api(array('method' => 'fql.query', 'query' => "SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) AND is_app_user = 1"));

var_dump返回:

array(5) {
  [0]=>
  array(1) {
    ["uid"]=>
    string(15) "100000670846118"
  }
  [1]=>
  array(1) {
    ["uid"]=>
    string(15) "100001811974704"
  }
  …
}
于 2012-09-04T10:57:55.647 回答