Android的 - 让Facebook的个人资料图片 [英] Android - get facebook profile picture

查看:134
本文介绍了Android的 - 让Facebook的个人资料图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

编辑:

所建议的<一个href="http://stackoverflow.com/questions/19855072/android-get-facebook-profile-picture#comment34682218_19855492">@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".

这篇关于Android的 - 让Facebook的个人资料图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆