如何通过 Facebook API 获取好友点赞

发布于 2024-10-14 09:37:19 字数 140 浏览 2 评论 0原文

这可以得到我所有朋友的喜欢吗?现在,我通过两个步骤得到了这个:

  1. 获取我所有的朋友列表
  2. 通过迭代这些列表,我得到了所有个人的喜欢,

但这似乎是一个非常大的过程,有人有想法提高这项任务的性能吗?

Is this possible to get all my friends likes?? Now, I'm getting this by 2 steps:

  1. Getting all my friends list
  2. By iterating those list I'm getting all individuals Likes,

but it seems very big process, anybody have idea to improve the performance for this task?

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

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

发布评论

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

评论(3

绝情姑娘 2024-10-21 09:37:20

使用 FQL 将比循环遍历 Graph API 结果更快。您可以获得朋友喜欢的页面的 ID,但不幸的是 FQL 不会返回除此之外的信息(即名称)。看看下面的内容。

这假设您使用具有 friends_likes 权限的 PHP SDK。

// hold on to your user ID
$user_id = $facebook->getUser();

// query your friend's likes based on their ID
$query = "SELECT uid, page_id FROM page_fan WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = $user_id)";
$result = $fb->api(array(
  'method' => 'fql.query',
  'query' => $query,
));

// optionally group the results by each friend ID
function arraySort($input, $sortkey){
  foreach ($input as $key => $val) {
    $output[ $val [ $sortkey ] ][] = $val;
  }
  return $output;
}
$friendLikes = arraySort($result,'uid');

// output the results
echo sprintf('<pre>%s</pre>', print_r($friendLikes,TRUE));

这样做的好处是您只需进行一次 API 调用。您必须分别拨打电话来获取好友姓名,并拨打另一个电话来获取喜欢的页面详细信息,但您现在可以通过直接的方法使用 ID。

Using FQL is going to be faster than looping through the Graph API results. You can get the ID of the pages your friends like, but unfortunately FQL does not return info other than that (ie the name). Take a look at the following.

This assumes you are using the PHP SDK with the friends_likes permission.

// hold on to your user ID
$user_id = $facebook->getUser();

// query your friend's likes based on their ID
$query = "SELECT uid, page_id FROM page_fan WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = $user_id)";
$result = $fb->api(array(
  'method' => 'fql.query',
  'query' => $query,
));

// optionally group the results by each friend ID
function arraySort($input, $sortkey){
  foreach ($input as $key => $val) {
    $output[ $val [ $sortkey ] ][] = $val;
  }
  return $output;
}
$friendLikes = arraySort($result,'uid');

// output the results
echo sprintf('<pre>%s</pre>', print_r($friendLikes,TRUE));

The benefit of this is that you only make one API call. You will have to make separate calls to get the friend names and another for the liked page details, but you have the IDs to work with now in a straight forward approach.

初见 2024-10-21 09:37:20

我相信这是唯一的办法。几周前我看过这个问题。不要认为他们改变了 API。

http://developers.facebook.com/docs/reference/api/

编辑:
我不确定我是否足够理解你的意思...如果你的意思是你想获取用户喜欢的帖子列表,你要做的是:

  1. 获取朋友的所有帖子
  2. 检查是否喜欢他们的任何帖子
  3. 获取所有帖子 检查
  4. 是否喜欢他/她自己的任何帖子
  5. 合并结果

这是您想要的吗?

I believe that is the only way. I looked at this problem a few weeks ago. Don't think they've changed the API.

http://developers.facebook.com/docs/reference/api/

EDIT:
I'm not sure I understand well enough what you mean... If you mean that you want to get a list of the posts that a user likes, what you have to do is this:

  1. Get all the posts by friends
  2. Check if likes any of their posts
  3. Get all the posts by
  4. Check if likes any of his/her own posts
  5. Combine the results

Is that what you want?

倾`听者〃 2024-10-21 09:37:19

我在查看 Facebook API 文档 2 周后终于找到了它

FB.api("/likes?ids=533856945,841978743")

FB.api("me/friends",{
  fields:'id',
  limit:10
},function(res){
  var l=''
  $.each(res.data,function(idx,val){
     l=l+val.id+(idx<res.data.length-1?',':'')
  })
  FB.api("likes?ids="+l,function(res){
      console.log(res);
  })
})

At last I found it after 2 weeks looking at Facebook API documentation

FB.api("/likes?ids=533856945,841978743")

FB.api("me/friends",{
  fields:'id',
  limit:10
},function(res){
  var l=''
  $.each(res.data,function(idx,val){
     l=l+val.id+(idx<res.data.length-1?',':'')
  })
  FB.api("likes?ids="+l,function(res){
      console.log(res);
  })
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文