Can';t通过Android下载Facebook用户档案图片

Can';t通过Android下载Facebook用户档案图片,android,facebook,Android,Facebook,我的问题是,我无法通过ID下载用户配置文件图片。当我使用浏览器和此URL时,我能够获得用户配置文件图片: 我可以看到此用户配置文件图片: 但是,当我想通过安卓系统获取这张照片时,我无法做到 // Execute the task new LoadImage().execute("http://graph.facebook.com/janno.hindrekson/picture?type=small"); } private class LoadImage extend

我的问题是,我无法通过ID下载用户配置文件图片。当我使用浏览器和此URL时,我能够获得用户配置文件图片:

我可以看到此用户配置文件图片:

但是,当我想通过安卓系统获取这张照片时,我无法做到

    // Execute the task
    new LoadImage().execute("http://graph.facebook.com/janno.hindrekson/picture?type=small");


}

private class LoadImage extends AsyncTask<String, String, Bitmap> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(TESTPROFILEPICT.this);
        pDialog.setMessage("Loading Image ....");
        pDialog.show();
    }

    protected Bitmap doInBackground(String... args) {
        try {
            bitmap = BitmapFactory.decodeStream((InputStream) new URL(args[0]).getContent());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bitmap;
    }

    protected void onPostExecute(Bitmap image) {
        if (image != null) {
            fbUserAvatar.setImageBitmap(image);
            pDialog.dismiss();
        } else {
            pDialog.dismiss();
            Toast.makeText(TESTPROFILEPICT.this, "Image Does Not exist or Network Error", Toast.LENGTH_SHORT).show();
        }
    }
}
//执行任务
新建LoadImage()。执行(“http://graph.facebook.com/janno.hindrekson/picture?type=small");
}
私有类LoadImage扩展了异步任务{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pDialog=新建进度对话框(TESTPROFILEPICT.this);
pDialog.setMessage(“正在加载图像…”);
pDialog.show();
}
受保护位图doInBackground(字符串…参数){
试一试{
bitmap=BitmapFactory.decodeStream((InputStream)新URL(args[0]).getContent());
}捕获(例外e){
e、 printStackTrace();
}
返回位图;
}
受保护的void onPostExecute(位图图像){
如果(图像!=null){
fbUserAvatar.setImageBitmap(图像);
pDialog.disclose();
}否则{
pDialog.disclose();
Toast.makeText(TESTPROFILEPICT.this,“图像不存在或网络错误”,Toast.LENGTH_SHORT.show();
}
}
}
有什么想法吗?我应该如何通过Android下载个人资料图片

谢谢,
凯文

我也有这个问题。尝试用相应的facebookId替换名称

new LoadImage().execute("http://graph.facebook.com/100001997422983/picture?type=small");
编辑

我意识到这个问题在stackoverflow上被问了好几次

不管怎样,原因是facebook重定向了这个url。因此,您必须调用重定向的url。 这是一个很好的例子:

或者您必须使用Facebook API:


我选择重定向方法,因为它是通用的,你可以从互联网上获取图像。

在Android上,如果你可以将Facebook SDK导入到你的项目中,有一种更简单的方法来完成这项任务

SDK中有一个名为Profile.getProfilePictureUri(int,int)的方法: