我正在尝试使用 social-auth android 库从 Facebook 获取用户个人资料照片。
我登录成功,在 ResponseListener 的 onComplete 登录后获得用户信息,我获得了用户个人资料图像 url,但是当我将其设置为 ImageView 时,我的 ImageView 变为空白。
这是我的代码。
mSocialAdapter = new SocialAuthAdapter(new ResponseListener());
mSocialAdapter.authorize(this,Provider.FACEBOOK);
private final class ResponseListener implements DialogListener{
@Override
public void onBack() {
}
@Override
public void onCancel() {
}
@Override
public void onComplete(Bundle bundle) {
mSocialAdapter.getUserProfileAsync(new SocialAuthListener<Profile>() {
@Override
public void onExecute(String arg0, Profile profile) {
if(profile.getDisplayName() != null)
Log.e("Display name", profile.getDisplayName());
if(profile.getProfileImageURL() != null){
Log.e("Profile Image Url", profile.getProfileImageURL());
Picasso.with(RegisterProfileSetupActivity.this).load(profile.getProfileImageURL()).into(imgUserPhoto);
//imgUserPhoto.setImageBitmap(loadImage(profile.getProfileImageURL()));
}
}
@Override
public void onError(SocialAuthError arg0) {
}
});
}
@Override
public void onError(SocialAuthError arg0) {
}
}
我也尝试这种方法来加载位图
public Bitmap loadImage(String url) {
DefaultHttpClient client = new DefaultHttpClient();
Bitmap bitmap = null;
try {
HttpResponse response = client.execute(new HttpGet(url));
HttpEntity entity = response.getEntity();
if(entity != null) {
InputStream in = entity.getContent();
bitmap = BitmapFactory.decodeStream(in);
}
}
catch (Exception e) {
}
return bitmap;
}