Facebook查询语言仅提供用户ID

时间:2011-07-01 11:01:08

标签: php facebook facebook-fql

我正在尝试打印使用我的应用程序的用户的朋友。使用Facebook查询语言(FLQ)来执行此操作。但查询只提供用户ID。如何获取带有个人资料图片的用户名

这是我的代码:

require 'facebook.php';

$facebook = new Facebook(array(
'appId'  => 'xxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxx',
'cookie' => true, // enable optional cookie support
));

$session = $facebook->getSession();
if ($session) {
try {
$some_friends = $facebook->api(array(
      'method' => 'fql.query',
      'query' => 'SELECT uid2 FROM friend WHERE uid1='.$facebook->getUser().' LIMIT 10'
    ));
} catch (FacebookApiException $e) {
error_log($e);
}
}
print_r($some_friends);

结果如下:

Array ( 
    [0] => Array ( [uid2] => 521117187 ) 
    [1] => Array ( [uid2] => 526583873 ) 
    [2] => Array ( [uid2] => 527579769 ) 
    [3] => Array ( [uid2] => 531219912 ) 
    [4] => Array ( [uid2] => 533654770 ) 
    [5] => Array ( [uid2] => 539141589 ) 
    [6] => Array ( [uid2] => 539243220 ) 
    [7] => Array ( [uid2] => 539342366 ) 
    [8] => Array ( [uid2] => 549294033 ) 
    [9] => Array ( [uid2] => 557508969 )
     )

...解决

3 个答案:

答案 0 :(得分:1)

你可以通过发布uid来获取他们的照片

http://graph.facebook.com/UID/picture

示例 http://graph.facebook.com/557508969/picture

enter image description here

得到他的名字 http://graph.facebook.com/557508969/(JSON编码)

答案 1 :(得分:0)

我认为您必须将选择查询更改为

SELECT id,username,profile_pic FROM friend WHERE uid1='.$facebook->getUser().' LIMIT 10'

如果我理解你的问题。

答案 2 :(得分:0)

require 'facebook.php';

$facebook = new Facebook(array(
'appId'  => 'xxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxx',
'cookie' => true, // enable optional cookie support
));

$session = $facebook->getSession();
if ($session) {
try {
$some_friends = $facebook->api(array(
      'method' => 'fql.query',
      'query' => 'SELECT uid,name,picture FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.$facebook->getUser().') LIMIT 10'
    ));
} catch (FacebookApiException $e) {
error_log($e);
}
}
print_r($some_friends);