Facebook 查询语言仅提供用户 ID

发布于 2024-11-17 19:53:49 字数 1181 浏览 2 评论 0原文

我正在尝试打印使用我的应用程序的用户的朋友。使用 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 )
     )

已解决...

I'm trying to print friends of user who uses my application.Using Facebook Query Language(FLQ) to do it. But query gives just user id's.How can i get usernames with profile pictures

Here is my code:

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);

Here is the result:

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 )
     )

solved...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暮倦 2024-11-24 19:53:49

you can get their picture by posting uid to

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

example
http://graph.facebook.com/557508969/picture

enter image description here

also his name by getting
http://graph.facebook.com/557508969/ (JSON encoded)

把时间冻结 2024-11-24 19:53:49

我认为如果我理解你的问题,你必须将你的选择查询更改为

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

i think you have to change your select query to

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

if i understood your question.

冰之心 2024-11-24 19:53:49

您需要使用 FQL 子查询,因为朋友表不包含有关用户的更多信息。试试这个:

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);

FQL Subqueries are what you need to be using, as the friend table doesn't contain any more information on the users. Try this:

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文