简体   繁体   English

如何使用Javascript SDK V2.0获取Facebook用户朋友的头像

[英]How to get Facebook user's friends' profile picture using Javascript SDK V2.0

I am creating a website using Facebook API V2.0 JavaScript SDK and I would like to display the profile pictures of the user's friends. 我正在使用Facebook API V2.0 JavaScript SDK创建一个网站,并且我想显示用户朋友的个人资料图片。 I have managed to display my profile picture using the graph API but I can't manage to get the ID of all my friends if I am logged in my app (I am an admin). 我已经使用图形API显示了我的个人资料图片,但是如果我登录了我的应用程序(我是管理员),则无法获得所有朋友的ID。 If I have the ID, I'll be able to show their profile picture. 如果我有ID,则可以显示其个人资料照片。

In the graph explorer , I have checked all permissions (User Data Permissions + Extended Permissions). 图资源管理器中 ,我检查了所有权限(用户数据权限+扩展权限)。 I have noticed if I switch to API V1.0, I get friends permission which is exactly what I'd like. 我已经注意到,如果我切换到API V1.0,则会得到朋友的许可,这正是我想要的。

Also, I have added a couple of permission to my app in Facebook developers > App details > App Center Listed Platforms > Configure app center permissions. 另外,我在Facebook开发人员>应用程序详细信息> App Center列出的平台>配置应用程序中心权限中为我的应用程序添加了一些权限。 (user_friends + friends_birthday + friends_religion_politics + friends_relationships + friends_relationship_details + friends_location + friends_photos + friends_about_me) (用户朋友+朋友生日+朋友宗教政策+朋友关系+朋友关系详细信息+朋友位置+朋友照片+朋友关于我)

So far, my html looks like this : 到目前为止,我的html看起来像这样:

<fb:login-button scope="public_profile,email,user_friends,read_friendlists" onlogin="checkLoginState();">

After loading the Facebook SDK, I have : 加载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"/>');
  });
  }

However, the array which is suppose to contain all my friends info is empty (see image : http://www.screencast.com/t/W02GaOm3h ) 但是,假定包含我所有朋友信息的数组为空(请参见图片: http : //www.screencast.com/t/W02GaOm3h

If all you need is their image, this can be found in the "taggable_friends" scope. 如果您只需要他们的图像,则可以在“ taggable_friends”范围内找到。 However, do note that this field is very limited (by design) and that you require additional review by Facebook in order to present it to the average user. 但是,请注意,此字段非常有限(根据设计),并且您需要Facebook进行其他审查才能将其呈现给普通用户。

It contains: 它包含:

  • A taggable id. 可标记的ID。 This is an id with the express purpose of tagging; 这是一个具有标记目的的id。 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. 网址,is_silhouette,高度和宽度。

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

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

A disclaimer: I've been battling with this issue for several days without really being able to mention-tag. 免责声明:我已经在这个问题上奋战了好几天,但实际上并没有提及标签。 My submission to use taggable_friends as a comprehensive, navigatable list for the user was rejected and I speculate (speculation ho!) it was because I did no actual tagging. 我提交的将taggable_friends用作用户的全面,可导航列表的提交被拒绝,我推测(推测ho!)这是因为我没有进行实际的标注。 I'll get back to this in a few days when I've clarified and re-submitted my request for a review on Facebook. 在几天后,我将在Facebook上澄清并重新提交我的审查请求后,再回到这一点。

-- Edit -- -编辑-

It would seem the reason my initial submission was rejected was because I was using a special development url and did not point out clearly enough why it was not enough to use the url set under settings. 似乎我的初次提交被拒绝的原因是因为我使用的是特殊的开发url,但没有足够清楚地指出为什么使用在设置下设置的url还不够。 This time I clearly pointed out and explained this reasoning in both the general description of my submission and in the step-by-step notes. 这次,我在我的意见书的一般说明和分步说明中都明确指出并解释了这种推理。 In summary, be exceptionally clear in your submission about everything; 总而言之,在提交的内容中要格外明确; your reasoning as to why you need this permission, how they can access it, etc. Just to make sure it isn't missed if skim-read. 您为何需要此许可权,他们如何访问该许可权的理由,等等。只是为了确保阅读时不会错过它。

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

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