15

i am using facebook SDK 3.0 i have to get profile picture of user login. Here is the code I use:

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

But I don't get the desired result.

5agado
  • 2,444
  • 2
  • 21
  • 30
Arun
  • 307
  • 1
  • 6
  • 12
  • 1
    i am also looking for same and not getting accurate profile picture used same code :) – user May 04 '13 at 09:15

8 Answers8

24

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/

akohout
  • 1,802
  • 3
  • 23
  • 42
Hai nguyen
  • 272
  • 4
  • 8
16

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());
Tulsiram Rathod
  • 1,926
  • 2
  • 19
  • 29
12

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.

Vishal Pawale
  • 3,416
  • 3
  • 28
  • 32
5

Use ProfilePictureView from facebook sdk.

Vishal Pawale
  • 3,416
  • 3
  • 28
  • 32
5
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();
}
Sanjay Mangaroliya
  • 4,286
  • 2
  • 29
  • 33
3

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.

2

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);
Sabyasachi
  • 3,499
  • 2
  • 14
  • 21
0

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/

kuhnp
  • 136
  • 1
  • 6