我不知道为什么,但是当我尝试获取用户的个人资料图片时,我总是得到空值。我是否需要设置一些特定的权限才能获得访问权限?
下面是我的方法:
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);
我得到空值。我不知道为什么?任何帮助都是可观的。
最佳答案
这应该可行:
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”。
关于Android - 获取 facebook 个人资料图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19855072/