我想获取facebook个人资料图片,但它返回Bitmap null。为什么? 调试我得到这个: 位图b = getUserPic(用户ID); b:null byte [] image = convertBitmapToByteArray(b); image:null
public void displayWelcomeMessage(Profile profile){
if (profile != null){
//mTextDetails.setText("Welcome "+ profile.getName());
databaseHelper = new Database(getActivity());
String name = profile.getName();
String idade = profile.getLastName();
String userIds = profile.getId();
Bitmap b = getUserPic(userIds);
byte[] image = convertBitmapToByteArray(b);
long id = databaseHelper.insertData(name, idade, image);
if(id < 0){
Message.message(getActivity(), "Unsuccessful");
} else{
Message.message(getActivity(), "Successfully Inserted a Row");
}
}
}
public Bitmap getUserPic(String userID) {
String imageURL;
Bitmap bitmap = null;
//Log.d(TAG, "Loading Picture");
imageURL = "https://graph.facebook.com/"+userID+"/picture?type=small";
try {
bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageURL).getContent());
} catch (Exception e) {
Log.d("TAG", "Loading Picture FAILED");
e.printStackTrace();
}
return bitmap;
}
答案 0 :(得分:1)
在
看看我的回答我认为这是因为Facebook在您拨打https://graph.facebook.com/"+userID+"/picture?type=small
时会发送重定向。
答案 1 :(得分:0)
试试这个:
URL url = new URL(imageURL);
Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());