如何使用Javascript SDK V2.0获取Facebook用户好友的个人资料照片

5
我正在使用Facebook API V2.0 JavaScript SDK创建网站,想要展示用户好友的个人资料图片。我已经成功地使用图形API显示了我的个人资料图片,但是如果我登录到我的应用程序中(我是管理员),我无法获取所有好友的ID。如果我有这些ID,我就能够显示他们的个人资料图片。
图形浏览器中,我已经检查了所有权限(用户数据权限+扩展权限)。我注意到,如果我切换到API V1.0,我会得到朋友的权限,这正是我想要的。
此外,我在Facebook开发者中心的应用详细信息>应用中心列出的平台>配置应用中心权限中添加了几个权限。(user_friends + friends_birthday + friends_religion_politics + friends_relationships + friends_relationship_details + friends_location + friends_photos + friends_about_me)
到目前为止,我的HTML代码如下:
<fb:login-button scope="public_profile,email,user_friends,read_friendlists" onlogin="checkLoginState();">

加载了Facebook SDK之后,我有:
function getUserFriends() {
  FB.api('me/friends?fields=first_name,gender,location,last_name', function (response) {
    console.log('Got friends: ', response);
    $("#friendslist").html('<img src="https://graph.facebook.com/'+ response.id+'/picture?type=large"/>');
  });
  }

然而,应该包含所有朋友信息的数组为空(见图片:http://www.screencast.com/t/W02GaOm3h)。

2
你的应用是在2014年4月30日之后创建的吗?如果是,那么你不能使用API v1.0。 - WizKid
嗨!感谢您的评论。是的,该应用程序是在2014年5月创建的,因此似乎我必须使用v2.0版本。 - Pierre ARNOU
1
好的,在API v2.0中,您只能访问使用您的应用程序的朋友(而不是所有朋友),并且已删除了所有friends_*权限。 - WizKid
2个回答

3
如果您只需要他们的头像,可以在“taggable_friends”范围内找到。然而,请注意,这个字段非常有限(出于设计目的),您需要Facebook进行额外的审核才能向普通用户展示它。
它包含以下内容:
  • A taggable id. This is an id with the express purpose of tagging; it cannot be used to identify the user or otherwise gather information from their profile.
  • A name. The user's first and last name.
  • A picture, with common related fields. Url, is_silhouette, height and width.

    function getUserFriends() {
      FB.api('me/taggable_friends', function (response) {
        console.log('Got friends: ', response.data);
        $("#friendslist").html('<img src="'+response.data[0].picture.data.url+'"/>');
        // maybe an $.each as well
        // var friendMarkup = '';
        // $.each(response.data, function(e, v) {
        //   friendMarkup += '<img src="' + v.picture.data.url +'" alt="'+ v.name +' picture"/>';
        // }
        // $("#friendlist").html(friendMarkup);
      });
    }
    

相关阅读:
https://developers.facebook.com/docs/graph-api/reference/v2.0/user/taggable_friends https://developers.facebook.com/docs/opengraph/using-actions/v2.0 - 标记朋友和提及朋友部分

免责声明:我已经为此问题奋斗了几天,但仍无法进行标记。我的提交使用taggable_friends作为用户的全面、可导航列表被拒绝了,我猜测(纯属猜测!)是因为我没有实际标记。几天后,当我在Facebook上澄清并重新提交请求进行审核时,我会回来的。

-- 编辑 --

似乎我最初的提交被拒绝的原因是因为我使用了一个特殊的开发url,并没有清楚地指出为什么不能使用设置下的url。这次我在提交的一般描述和逐步说明中都清楚地指出和解释了这个理由。总之,在你的提交中要非常清楚地说明所有事情;你需要这个权限的理由,他们如何访问它等等。以防被忽略掉。



网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接