3

我正在编写使用 facebook api 的 android 应用程序,我需要我的应用程序可以检索用户个人资料图片。

这是我目前的权限:

fb_login_button.setReadPermissions(Arrays.asList("public_profile", "user_friends"));

但我在文档中没有看到任何获取用户个人资料图片的权限,而只有访问所有图片的权限(我对此不感兴趣)。因此,个人资料图片现在无需任何许可即可访问

4

2 回答 2

3

public_profile 权限也可以为您提供个人资料图片。

这就是你将如何获得个人资料图片

public static Bitmap getFacebookProfilePicture(String userID){
URL imageURL = new URL("https://graph.facebook.com/" + userID + "/picture?type=large");
Bitmap bitmap = BitmapFactory.decodeStream(imageUrl.openConnection().getInputStream());

return bitmap;
 }

 Bitmap bitmap = getFacebookProfilePicture(userId);

参考:Android - 获取 facebook 头像

于 2014-07-24T09:02:41.783 回答
1

您不需要任何特殊权限即可获取个人资料图片。使用权限“public_profile”,您可以获得用户的 ID。如果你有用户 id ,你可以使用 graph api 来获取头像,如下。

http://graph.facebook.com/user_id/picture?type=square&redirect=false

如果你使用redirect=false,你会得到如下的json。

{
   "data": {
      "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xaf1/t1.0-1/c92.62.775.775/s50x50/564992_463610327023364_1165619683_n.jpg",
      "is_silhouette": false
   }
}

json 中的“url”会给出用户的头像。您也可以在不重定向的情况下使用它。

于 2014-07-24T09:03:58.393 回答