Pregunta

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

¿Fue útil?

Solución

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

Otros consejos

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

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top