2

I am using below code to get profile image of friends using Resfb. I get the response too with name id and image. Please some one help me asap on how to get the image from this data.

Code

Connection<User> myFriends = facebookClient.fetchConnection("me/friends", User.class,Parameter.with("fields", "id, name,picture"));

Response

"data":[{"id":"554603591","name":"Arjun Rao","picture":"http:\/\/profile.ak.fbcdn.net\/hprofile-ak-snc4\/211391_554603591_2022493_q.jpg"}"

Thanks

Vinay
  • 6,890
  • 4
  • 31
  • 50

3 Answers3

0

You know how to parse the response?

If yes, just get the URL of the image, open a URLConnection and do a getInputStream() (the code for this is in this SO answer).

With the InputStream, you can save to a file or send it to the client.

Community
  • 1
  • 1
blop
  • 103
  • 9
  • 1
    Consider adding context for the link. See [How to Answer](http://stackoverflow.com/questions/how-to-answer) for details why. – bytebuster Oct 20 '12 at 01:22
  • I think this is a fine answer. I'm not here to judge whether it's right or wrong, but in terms of *quality*, it looks just fine. – Zizouz212 Feb 18 '16 at 23:25
0

You can use restfb to parse Json-Objects:

JsonObject obj = new JsonObject(SERVER_RESPONSE);
try {
     String pictureURL = obj.getString("picture");
    }
catch(JsonException e) {
       // key 'picture' not found
       e.printStackTrace();
}
Max
  • 16
0

Could it be that RestFB isn't up to date in sense how Graph API returns (some objects) inside "data" object?

I managed to work-around with this custom class:

public class DataPictureHolder {
    @Facebook("data")
    public ProfilePictureSource picture;
}
Render
  • 2,059
  • 2
  • 15
  • 14