Android - 获取 facebook 个人资料图片

标签 android facebook profile

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

下面是我的方法:

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/

相关文章:

java - 导入com.facebook.android.R;未找到

powershell - 如何在 PowerShell 中从脚本文件重新加载用户配置文件

带有左右轨道图像的 Android 自定义 ProgressBar

android - 如何用两个手指滚动位图?

facebook - 如何通过 Facebook API 发布包含多张照片的状态?

javascript - FB.login 限制弹出窗口被阻止

export - 带描述的 Sonar 质量配置文件规则导出

path - brew : Consider setting your PATH so that/usr/local/bin occurs before/usr/bin

java - 按下后退按钮并再次打开应用程序后媒体播放器崩溃

Android GridView 元素在行中重叠