Android的 - 让Facebook的个人资料图片个人资料、图片、Android、Facebook

2023-09-12 07:19:50 作者:繁华殆尽落一地悲伤

我不知道为什么,但我总是得到空当我尝试获取用户的个人资料图片。我是否需要设置一些权限可以访问?

I don't know why, but I am always getting null when I try to get user profile picture. Am I need to set some permission to get access?

这是我的方法:

public static Bitmap getFacebookProfilePicture(String userID) throws SocketException, SocketTimeoutException, MalformedURLException, IOException, Exception
{
   String imageURL;

   Bitmap bitmap = null;
   imageURL = "http://graph.facebook.com/"+userID+"/picture?type=large";
   InputStream in = (InputStream) new URL(imageURL).getContent();
   bitmap = BitmapFactory.decodeStream(in);

   return bitmap;
}

Bitmap bitmap = getFacebookProfilePicture(userId);

我越来越空。我不知道为什么。

I am getting null. I don't know why.

推荐答案

这应该工作:

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

编辑:

所建议的@dvpublic在评论中,图像不被下载的问题是使用以https开头赞成固定的HTTP。

As suggested by @dvpublic in the comments, the problem of image not being downloaded is fixed using by "https" in favour of "http".