How to get facebook profile picture of user in facebook SDK 3.0 Android

两盒软妹~` 提交于 2019-11-30 00:29:48
Hai nguyen

You should change your code following:

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

Possible GET parameters for the URL can be found here: https://developers.facebook.com/docs/graph-api/reference/user/picture/

Use https:// instead of http:// i faced the same problem.

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

If you are trying to display profile pic in your app, use ProfilePictureView from Facebook SDK.

Refer This

Just call setProfileId(String profileId) on it.

It will take care of displaying the image.

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();
}

Use ProfilePictureView from facebook sdk.

You can do something like this inside a thread:

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();

I hope it help you.

try this..

 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);

Once your facebook account is logged into the application, simply do:

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

x and y are width and height.

See the doc : https://developers.facebook.com/docs/reference/android/current/class/Profile/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!