如何在facebook SDK 3.0 Android中获取用户的facebook个人资料图片

时间:2013-05-04 09:09:41

标签: android facebook facebook-android-sdk

我正在使用facebook SDK 3.0我必须获得用户登录的个人资料图片。 这是我使用的代码:

URL image_value = new URL("http://graph.facebook.com/"+id+"/picture" );
profPict=BitmapFactory.decodeStream(image_value.openConnection().getInputStream());

但我没有得到理想的结果。

8 个答案:

答案 0 :(得分:24)

您应该更改以下代码:

URL image_value = new URL("http://graph.facebook.com/"+id+"/picture" );

可以在此处找到URL的可能GET参数: https://developers.facebook.com/docs/graph-api/reference/user/picture/

答案 1 :(得分:16)

使用 https:// 代替 http:// 我遇到了同样的问题。

URL image_value = new URL("https://graph.facebook.com/"+id+"/picture" );
profPict = BitmapFactory.decodeStream(image_value.openConnection().getInputStream());

答案 2 :(得分:12)

如果您要在应用中显示个人资料照片,请使用Facebook SDK中的ProfilePictureView

Refer This

只需拨打setProfileId(String profileId)即可。

它将负责显示图像。

答案 3 :(得分:6)

String id = user.getId();
try {
  URL url = new URL("http://graph.facebook.com/"+ id+ "/picture?type=large");
  String image_path = uri.toString();
  System.out.println("image::> " + image_path);
}
catch (MalformedURLException e) {
  e.printStackTrace();
}

答案 4 :(得分:5)

使用facebook sdk中的ProfilePictureView

答案 5 :(得分:2)

你可以在一个帖子里做这样的事情:

String url = "http://graph.facebook.com/"+id+"/picture";
HttpConnection conn = new HttpConnection(url);
conn.openConnection();

Drawable d = Drawable.createFromStream(new BufferedInputStream(conn.getInputStream()), "image");

conn.close();

我希望它可以帮到你。

答案 6 :(得分:2)

试试这个..

 try {
        imageURL = new URL("https://graph.facebook.com/" +
                                                id+ "/picture?type=large");
        Log.e("URL", imageURL.toString());
        } catch (MalformedURLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
             try {
                    bitmap = BitmapFactory.decodeStream(imageURL
                                .openConnection().getInputStream());
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }

      ProfileDp.setImageBitmap(bitmap);

答案 7 :(得分:0)

一旦您的Facebook帐户登录到应用程序,只需执行以下操作:

String url = Profile.getCurrentProfile().getProfilePictureUri(x, y).toString();

x和y是宽度和高度。

请参阅文档:https://developers.facebook.com/docs/reference/android/current/class/Profile/