简体   繁体   English

使用Facebook API获取所有朋友和喜欢的人

[英]Get all friends and their likes using the Facebook API

I'm just getting started with a project and wondered if someone can let me know if it's possible to: 我刚开始一个项目,想知道是否有人可以让我知道是否可以:

A) Get a list of all friends for an authorised Facebook account via the API A)通过API获取授权的Facebook帐户的所有朋友的列表

B) Get all of the likes for each friend using the API B)使用API​​获得每个朋友的所有喜欢

I saw this code suggested on another question: 我在另一个问题上看到了建议的代码:

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

But I'm struggling to understand the logic of this as it looks like you need to know the ids to get the likes. 但是我很难理解它的逻辑,因为您似乎需要知道ids才能获得喜欢。

Also is there a limit to the number of likes returned? 返回的点赞次数是否有限制? I read something about it only returning the last X number of likes for each user. 我读到一些有关它的信息,但只返回了每个用户的最近X个点赞。

Many thanks! 非常感谢!

You can fetch all the friends for an authorized user with the friends.get API call. 您可以通过friends.get API调用获取授权用户的所有朋友。 http://developers.facebook.com/docs/reference/rest/friends.get/ http://developers.facebook.com/docs/reference/rest/friends.get/

Once you have the list of friends, you can loop through the list and fetch their likes by using the graph API's "likes" call. 获得好友列表后,您可以遍历列表并使用图形API的“喜欢”调用获取他们的喜欢。

Graph API Documentation: http://developers.facebook.com/docs/reference/api/ Graph API文档: http : //developers.facebook.com/docs/reference/api/

Sample "likes" request: https://graph.facebook.com/put_a_fb_user_id_here/likes 样本“喜欢”请求: https : //graph.facebook.com/put_a_fb_user_id_here/likes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM