如何在 Facebook Graph API 中获取好友详细信息?

发布于 2024-10-15 04:55:30 字数 300 浏览 3 评论 0原文

如何获取两个人的友谊详细信息?例如,在网络中它将是:

http://www.facebook.com/<my_id>?and=<friend_id>

有什么方法可以在 Graph API 中做到这一点吗?此外,我可以获取特定物品,例如在一起的照片、我们之间的墙贴等吗? (据我所知,没有记录,但许多 Graph API 功能无论如何都不是......)

编辑:我认为 Graph API 应该可以实现。例如,获取家庭详细信息(兄弟、姐妹、父母等)没有记录在案,但我仍然能够做到。

How can I get a friendship detail for two people? So for example in the web it will be:

http://www.facebook.com/<my_id>?and=<friend_id>

Is there any way I can do this in Graph API? Furthermore can I get specific items such as photos together, wall posts between us, etc? (Not documented AFAIK, but many Graph API features aren't anyway...)

EDIT: I think it should be possible with Graph API. For example getting family details (brother, sister, parents, etc) is not documented yet I still able to do it.

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

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

发布评论

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

评论(6

柳若烟 2024-10-22 04:55:30

您可以通过执行多个 FQL 查询来模拟友谊查询。例如,要获取两个好友 A 和 B 之间的所有照片,可以:

  1. 获取 A 的所有照片(p)
  2. 获取 p 中 B 的所有标签(在 photo_tags 表上查询)
  3. 获取 B 对 p 的所有评论(查询(在评论表上)

重复,这次选择 B 中的照片。

您可以将相同的概念应用于其他事物,例如帖子、点赞、视频等。

You can simulate a friendship query by doing multiple FQL queries. For example, to get all the photos between two friends A and B, you can:

  1. Get all photos (p) from A
  2. Get all tags of B in p (query on the photo_tags table)
  3. Get all comments made by B on p (query on the comments table)

Repeat, this time selecting photos from B.

You can apply the same concept on other things such as posts, likes, videos etc.

清眉祭 2024-10-22 04:55:30

是的,我认为您也可以使用 Graph API 而不是 FQL 做同样的事情 phillee 回答:

  1. 获取用户的照片 https://graph.facebook.com/USERID/photos
  2. 获取每张照片的标签 https://graph.facebook.com/PHOTOID/tags
  3. 对照片标签列表进行排序,并抓取其中包含好友的所有照片
  4. 获取每张照片的评论 https ://graph.facebook.com/PHOTOID/comments
  5. 对照片评论列表进行排序,并抓取朋友留下的所有评论
  6. 正如另一个答案也所说:冲洗并重复您想要的所有数据
    1. https://graph.facebook.com/USERID/feed
    2. https://graph.facebook.com/USERID/posts
    3. 等等,请在此处查看所有连接:http://developers.facebook.com/docs/reference/api/user/

对于兴趣、电影、活动等,只需对两者进行 API 调用(https:// /graph.facebook.com/ONEUSER/musichttps://graph.facebook.com/OTHERUSER/music)并找到两组数据的交集(循环遍历每组数据)列出所有匹配项并将其保存到单独的相互喜欢列表中)

不过,没有针对友谊的特定 API 调用,因此您必须构建自己的 API。我的猜测是 Facebook 在他们的友谊页面上正是这样做的:)

使用 FQL 应该和使用 REST API 一样简单...使用 FQL 甚至更容易,因为您可以添加 WHERE 条件并只返回您需要的数据(SELECT * FROM comments WHERE fromid = FRIENDID),而不是对 API 返回的大列表进行排序(除非有办法向 API 请求 URL 添加条件?)。

Yes, I think you can also do the same thing phillee answered with the Graph API instead of FQL:

  1. Get user's photos https://graph.facebook.com/USERID/photos
  2. Get each photo's tags https://graph.facebook.com/PHOTOID/tags
  3. Sort through the list of photo tags, and grab all photos with the Friend in them
  4. Get each photo's comments https://graph.facebook.com/PHOTOID/comments
  5. Sort through the list of photo comments, and grab all comments left by the friend
  6. As the other answer also said: rinse and repeat for all data you want
    1. https://graph.facebook.com/USERID/feed
    2. https://graph.facebook.com/USERID/posts
    3. etc etc, see all connections here: http://developers.facebook.com/docs/reference/api/user/

For the interests, movies, activities, etc just make an API call for both (https://graph.facebook.com/ONEUSER/music and https://graph.facebook.com/OTHERUSER/music) and find the intersection of the two sets of data (loop through each list and save all matches to a separate list of mutual Likes)

There are no specific API calls for friendships though, so you will have to build your own. My guess is that Facebook is doing exactly this on their Friendship pages :)

It should be just as easy with FQL as with the REST API... maybe even easier with FQL since you can add WHERE conditions and get back just the data you need (SELECT * FROM comments WHERE fromid = FRIENDID), instead of sorting through the big list returned by the API (unless there is a way to add conditions to API request URLs?).

快乐很简单 2024-10-22 04:55:30

如果我理解正确的话,您想要“查看友谊”

这种类型的查询不能直接使用图形 API(目前)。您需要从每个资源端点收集信息,然后自行执行一些与“查看友谊”相关的操作

If I understand properly you want to "View Friendship"

This type of query is not directly possible using the Graph API (at the moment). You would need to gather the information from each resource endpoint and then do some relating on your own part to "View Friendship"

绮烟 2024-10-22 04:55:30

这就是我一直在使用的:

<?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()!

This is what I have been using:

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

Call main()!

尽揽少女心 2024-10-22 04:55:30

获取两个(或更多)用户被标记的照片:

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

Getting the photos where two (or more) users are tagged in:

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