16

EDIT: Anwser at the end of this post.

I am trying to get a Facebook user's profile picture thanks to the inbuilt Facebook SDK's function Request().

I am using a /me/picture call to get the profile picture and convert it into a Bitmap.

The call is working fine but I don't know how to interpret and parse the result returned from Facebook

Here is the JSON that I get:

{ "FACEBOOK_NON_JSON_RESULT" : "����\u0000\u0010JFIF\u0000\u0001\u0002\u0000\u0000\u0001\u0000\u0001\u0000\u0000��\u0000\u0004*\u0000��\u0000C\u0000\u0006\u0004\u0005\u0006\u0005\u0004\u0006\u0006\u0005\u0006\u0007\u0007\u0006\b" }

I think this should be representing the profile picture but I don't know what to do with this now.

If somebody could tell me either how to decode it, convert it to a Bitmap or what kind of data it is, I would be grateful.

NOTES: I don't want to use any other function than Request(), like DecodeStream() or an AsyncTask


Here is the answer:

When making a new Request() you need to add the "redirect" parameter to false:

Bundle params = new Bundle();
params.putBoolean("redirect", false);

This will return the correct picture URL:

{
"data":{
      "is_silhouette":false,
      "url":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-xpa1\/v\/t1.0-1\/p100x100\/10312434_10152395442477210_2933994167675146084_n.jpg?oh=f3c8cb920c97fcfa4dc5e17462445cbf&oe=54404A3A&__gda__=1412730795_5f288e34e5f6e63cb1c3791dcb142880"
   }
}
Aziule
  • 441
  • 3
  • 12

1 Answers1

3

Try this :

ImageView user_picture;
userpicture=(ImageView)findViewById(R.id.userpicture);
URL img_value = null;
img_value = new URL("http://graph.facebook.com/"+id+"/picture?type=large");
Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
userpicture.setImageBitmap(mIcon1);

Where ID is one your profile ID.

For Further details check this :

https://developers.facebook.com/docs/graph-api

VVB
  • 7,363
  • 7
  • 49
  • 83
  • this answer got me going in the right direction, thanks! Using the GraphApi callback - for the url, this is what worked for me: `String picUrlString = (String) response.getJSONObject().getJSONObject("data").get("url");`. From this post: https://dennisegert.wordpress.com/2015/08/16/android-facebook_non_json_result-when-trying-to-retrieve-the-profile-picture/ – Gene Bo Oct 07 '16 at 03:52