我如何获取两个人之间的好友关系详细信息?例如在Web上:
http://www.facebook.com/<my_id>?and=<friend_id>
我能否在Graph API中实现这一点?此外,我能否获取特定项目,例如我们之间的照片、墙上的帖子等?(据我所知未经记录,但许多Graph API功能也无法记录...)
编辑:我认为使用Graph API应该是可能的。例如,获取家庭详细信息(兄弟姐妹、父母等)尚未记录,但我仍然可以做到。
我如何获取两个人之间的好友关系详细信息?例如在Web上:
http://www.facebook.com/<my_id>?and=<friend_id>
我能否在Graph API中实现这一点?此外,我能否获取特定项目,例如我们之间的照片、墙上的帖子等?(据我所知未经记录,但许多Graph API功能也无法记录...)
编辑:我认为使用Graph API应该是可能的。例如,获取家庭详细信息(兄弟姐妹、父母等)尚未记录,但我仍然可以做到。
是的,我认为您也可以使用Graph API而不是FQL来完成相同的操作,就像phillee
所回答的那样:
https://graph.facebook.com/USERID/photos
https://graph.facebook.com/PHOTOID/tags
https://graph.facebook.com/PHOTOID/comments
https://graph.facebook.com/USERID/feed
https://graph.facebook.com/USERID/posts
http://developers.facebook.com/docs/reference/api/user/
对于兴趣、电影、活动等,只需调用API(https://graph.facebook.com/ONEUSER/music
和https://graph.facebook.com/OTHERUSER/music
),并找到两组数据的交集(遍历每个列表并将所有匹配项保存到一个单独的互相喜欢列表中)
虽然没有特定的API调用来获取好友关系,但您需要自己构建。我猜Facebook在他们的友谊页面上也是这样做的 :)
使用FQL和REST API一样容易...甚至更容易,因为您可以添加WHERE条件并仅返回所需的数据(SELECT * FROM comments WHERE fromid = FRIENDID
),而不是浏览API返回的大列表(除非有一种方法将条件添加到API请求URL中?)。
获取被两个(或更多)用户标记的照片:
SELECT pid, src_big FROM photo
WHERE pid IN(
SELECT pid FROM photo_tag WHERE subject=me())
AND pid IN(
SELECT pid FROM photo_tag WHERE subject=FRIEND_ID)
AND pid IN(
SELECT pid FROM photo_tag WHERE subject=ANOTHER_FRIEND_ID)
...
如果我理解正确,您想要“查看友谊”
目前,使用Graph API直接查询此类信息是不可能的。您需要从每个资源端点收集信息,然后在自己的部分进行一些关联才能“查看友谊”。
这是我一直在使用的:
<?php
function main()
{
global $Fb;
$Fb = new Facebook(array('appId'=>FB_API_ID,'secret'=>FB_API_SECRET));
$logoutUrl = $Fb->getLogoutUrl();
$loginUrl = $Fb->getLoginUrl();
$user = fb_loguser($Fb);
if ($user)
{
$txt .= "<p align=\"center\"><a href=\"" . $logoutUrl . "\">Logout</a></p>";
$txt .= "<h3 align=\"center\">You</h3>";
$access_token = $Fb->getAccessToken();
$user_profile = $Fb->api('/me');
$txt .= "<p align=\"center\">
<img src=\"https://graph.facebook.com/".$user."/picture\"></p>";
$txt .= fb_friends_list($user_profile,$access_token);
}
}
function fb_loguser($facebook)
{
global $Fb;
$Fb = $facebook;
$user = $Fb->getUser();
if ($user)
{
try
$user_profile = $Fb->api('/me');
catch (FacebookApiException $e)
{
error_log($e);
$user = null;
}
}
return($user);
}
function fb_friends_list($access_token)
{
global $Sess,$Fb;
$friends = $Fb->api('/me/friends'); // return an array [data][0 to n][name]/[id]
$siz = sizeof($friends['data']);
$txt = "<h3>Your FRIENDS on FACEBOOK</h3>";
$txt .= "<table>";
for ($i=0; $i<$siz; $i++)
{
$fid = $friends['data'][$i]['id'];
$src = "http://graph.facebook.com/".$fid."/picture";
$txt .= "<tr><td><img src=\"".$src."\" /></td>";
$txt .= "<td>".$friends['data'][$i]['name'] . "</td>";
$txt .= "<td>" . $fid . "</td></tr>";
}
$txt .= "</table>";
return($txt);
}
?>
调用 main()!
http://bighnarajsahu.blogspot.in/2013/03/facebook-graph-api-to-get-user-details.html
这是获取 Facebook 好友列表的完整代码。