I don't know why, but I am always getting null when I try to get the profile picture of the user. Do I need to set some specific permissions to get access?
Below is my method:
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 the reason why? Any help is appreciable.
This should work:
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);
As suggested by @dvpublic in the comments, the problem of image not being downloaded is fixed using by "https" in favour of "http".