如何从我的朋友列表中获取Facebook用户名。?

时间:2012-06-28 03:59:39

标签: facebook facebook-graph-api

我想在朋友列表中获取用户的用户名。我怎样才能做到这一点?

我正在使用

https://graph.facebook.com/me/friends&access_token=...

这会给我一个json response的所有姓名和ID号码?我想以某种方式获取用户名(非用户ID)?

我有一种方法可以访问每个ID,然后获取userName,但考虑到我有500个朋友,这将需要很长时间。是否有一些更短的方式/更简单的方法来做到这一点?

2 个答案:

答案 0 :(得分:2)

在字段参数中询问用户名:

https://graph.facebook.com/me/friends?fields=username&access_token=...

答案 1 :(得分:0)

我似乎无法在API中找到任何内容来获取用户配置文件列表。但一种可能的解决方案是使用批量请求。您可以将每个单独的用户配置文件请求合并为一个大批量。它仍然很麻烦,但比为每个朋友单独发出HTTP请求更好。

http://developers.facebook.com/blog/post/2011/03/17/batch-requests-in-graph-api/

例如:

  $batched_request = '[
    {"method":"GET","relative_url":"friend_id_1"},'.'{"method":"GET","relative_url":"friend_id_2"}
  ]';

  $post_url = "https://graph.facebook.com/" . "?batch=" . $batched_request
  . "&access_token=" . $access_token . "&method=post";