开发者

How to fetch the friends of my friends using the Facebook API?

I have an application where users can register themselves using Facebook credentials. Now consider for every user I get the permission for offline access.

I know that I can fetch the friends of mine using the Graph API.. For every user registered, I store the fbuid into my database.

Now I'm thinking that as I have my friends who have registered into my application and those users would have permitted my application for offline access. I thought of getting my friends in an array and just find friends of each and every friend in the array and join all of them.. Here the problem is I need to remove the Facebook users who are repeated (may be a friends in too many friend's list) and get a final list of friends of friends..

So can I get the friends of my friend using FQL or Graph API?


I searched/read lots of topics on Stack Overflow by searching for 开发者_JAVA技巧friends of friends, but of no use.

Note: This is not the similar questions already posted on Stack Overflow. Please read fully to understand this question.


You can't use the FQL table 'friends' to get friends of friends, you need a valid access token for every friend which you don't have.

You can do this with the graph API easily, but it will probably take a long time. My guess is 20 minutes average for 500 friends. You will need to call this:

https://graph.facebook.com/USER_ID?fields=id

First for the original user, and then for every one of his friends. The fields=id parameter will help with the amount of data you receive, though you will probably need to set the limit higher too. Add &limit=5000 to the graph query.

To save on time you can use Batch Requests. First call the friends connection for the original user, and then generate a batch request for all his friends. All this will generate a lot of data, so doing it on the fly is probably not a good idea.

There is no way for Facebook to sort all the duplicates for you, you will need to do so manually with the programming language you are using, but that should be trivial.

Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜