php 我可以使用 Facebook graph api 来获取用户的好友个人资料图片吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3882573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I use the Facebook graph api to get user's friends profiles pictures?
提问by José Joel.
I'm new to facebook development, after testing the adobe api in a flash game I decided to test using the graph api communicating with my flash game. After doing basic stuff like connecting and getting my user's data, i was wondering if it's posible to get my user's friends profile pcitures, so i can pass them to UILoaders inside my flash game and show them.
我是 facebook 开发的新手,在 Flash 游戏中测试了 adobe api 后,我决定使用与我的 Flash 游戏通信的图形 api 进行测试。在完成连接和获取用户数据等基本操作后,我想知道是否可以获取我用户的朋友个人资料图片,以便我可以将它们传递给我的 Flash 游戏中的 UILoaders 并显示它们。
If anyone can point me to examples of basic actions which use the facebook graph api, like invite friends or posting to the wall for example, that would be wonderful.
如果有人可以向我指出使用 facebook graph api 的基本操作示例,例如邀请朋友或发布到墙上,那就太好了。
thanks.
谢谢。
update:
更新:
Using Nathan's suggestion I tried to get my friends and it worked:
使用 Nathan 的建议,我试图让我的朋友们成功:
$friends= $facebook->api('/me/friends?token='.$session['access_token']);
var_dump($friends);
Then I tried to get my friend's pictures with:
然后我尝试使用以下方法获取我朋友的照片:
foreach ($friends['data'] as $friend)
{
$picture= $facebook->api('/'.$friend['id'].'/photo');
}
But it didn't work. any idea ?
但它没有用。任何的想法 ?
Thanks.
谢谢。
回答by darki699
Easiest way yet was not posted here:
最简单的方法尚未发布在这里:
https://graph.facebook.com/me/friends?access_token=[oauth_token]&fields=name,id,picture
回答by Nathan Totten
You first have to get the list of friends https://graph.facebook.com/me/friends?access_token=... then for each of the friends you can request http://graph.facebook.com/user_id/pictureThat will give you the url of their current profile photo.
您首先必须获得朋友列表https://graph.facebook.com/me/friends?access_token=... 然后对于每个朋友,您可以请求http://graph.facebook.com/user_id/picture这将为您提供他们当前个人资料照片的网址。
回答by alcaprar
I was looking for the same functionality and just noticed that it is not possible anymore (at the time of writing: 2019-11-17, api v5.0).
我正在寻找相同的功能,只是注意到它不再可能了(在撰写本文时:2019-11-17,api v5.0)。
If you try to call /me/friends?fields=friends{name,id,profile_pic}
you would receive an empty array of friends:
如果你尝试打电话,/me/friends?fields=friends{name,id,profile_pic}
你会收到一个空的朋友数组:
{
"data": [
],
"summary": {
"total_count": 823
}
}
Graph explorer shows this debug message: Only friends who installed this app are returned in API v2.0 and higher. total_count in summary represents the total number of friends, including those who haven't installed the app.
图形资源管理器显示此调试消息: Only friends who installed this app are returned in API v2.0 and higher. total_count in summary represents the total number of friends, including those who haven't installed the app.
回答by UmutKa
It's not possible to get the photos this way : /'.$friend['id'].'/photo
以这种方式获取照片是不可能的: /'.$friend['id'].'/photo
Instead you have to loop through the albums first using : /'.$friend['id'].'/albums
相反,您必须首先使用以下方法循环浏览专辑: /'.$friend['id'].'/albums
Then for each album id you should use : /'.$album['id'].'/photos
然后对于每个专辑 ID,您应该使用: /'.$album['id'].'/photos
This way you will reach the ID's of the pictures in that album. Then with the picture Id you had, you can get the photo /'.$picture['id'].'/picture
通过这种方式,您将获得该相册中图片的 ID。然后用你的图片ID,你可以得到照片/'.$picture['id'].'/picture
Hope this helps.
希望这可以帮助。
回答by Ahmed Ghoneim
foreach ($friends['data'] as $friend)
{
$picture= $facebook->api('/'.$friend['id'].'/photo?token='.$session['access_token']);
}
回答by Khalil Kitar
I'm using http://facebook4j.org/en/code-examples.htmland it's too simple.
我正在使用http://facebook4j.org/en/code-examples.html,它太简单了。
example :
例子 :
System.out.println("picture of publisher : "+facebook.getPictureURL(feed.get(41).getFrom().getId()));