我正在使用 Facebook API V2.0 JavaScript SDK 创建一个网站,我想显示用户 friend 的个人资料图片。 我已经设法使用图形 API 显示我的个人资料图片,但如果我登录我的应用程序(我是管理员),我无法获取所有 friend 的 ID。如果我有 ID,我将能够显示他们的个人资料照片。
在graph explorer ,我检查了所有权限(用户数据权限+扩展权限)。我注意到如果我切换到 API V1.0,我会得到 friend 的许可,这正是我想要的。
此外,我在 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"/>');
});
}
然而,假设包含我所有 friend 信息的数组是空的(见图:http://www.screencast.com/t/W02GaOm3h)
最佳答案
如果您只需要他们的图片,可以在“taggable_friends”范围内找到。但是,请注意,此字段非常有限(按设计),您需要 Facebook 进行额外审核才能将其呈现给普通用户。
它包含:
- 可标记的 ID。这是一个具有明确标记目的的 id;它不能用于识别用户或以其他方式从他们的个人资料中收集信息。
- 一个名字。用户的名字和姓氏。
一张图片,具有共同的相关领域。网址、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); }); }
相关阅读:
https://developers.facebook.com/docs/graph-api/reference/v2.0/user/taggable_friends
https://developers.facebook.com/docs/opengraph/using-actions/v2.0 - 标记 friend 和提及 friend 部分
免责声明:几天来我一直在与这个问题作斗争,却无法真正提及标签。我提交的使用 taggable_friends 作为一个综合的、可导航的用户列表被拒绝了,我推测(猜测 ho!)这是因为我没有做实际的标记。几天后,当我澄清并重新提交我在 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. 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.
关于javascript - 如何使用Javascript SDK V2.0获取Facebook用户好友头像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23745919/