0

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

我在用

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

这是返回给我一个json response包含所有名称和 ID 号的信息吗?我想以某种方式获取用户名(不是用户 ID)?

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

4

2 回答 2

2

在 fields 参数中询问用户名:

https://graph.facebook.com/me/friends?fields=username&access_token=...
于 2012-06-28T06:07:57.983 回答
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";
于 2012-06-28T04:24:58.387 回答