Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get profile image url from Facebook with spring-social?

I use spring-social-facebook to interact with Graph API (1.0.3.RELEASE if it's metter).
And I can't find any operation to retrieve profile's image url. I found only operations which return array of bytes and they are not very convenient for the implementation.
Does any kind of operation which retrieves image url exist in Spring Social?
If not, is there any 'tidy' workaround for this?
Thanks!

like image 853
Vladimir Filipchenko Avatar asked Feb 11 '14 15:02

Vladimir Filipchenko


2 Answers

i just ran into same issue, hope this will help someone else

Connection<Facebook> connection = userConnectionRepository.findPrimaryConnection(Facebook.class);
connection.createData().getImageUrl()
like image 32
user3698061 Avatar answered Nov 17 '22 06:11

user3698061


Finally, I didn't find any mention of profile picture url in spring social
My solution:
Initially I planned to extend UserOperations (FacebokTemplate.userOperations) class and add new method. But it's a package-level class and doens't visible outside.
So I decided to create my own template class extending FacebookTemplate and implement the method in this way:

public String fetchPictureUrl(String userId, ImageType imageType) {
    URI uri = URIBuilder.fromUri(GRAPH_API_URL + userId + "/picture" +
            "?type=" + imageType.toString().toLowerCase() + "&redirect=false").build();

    JsonNode response = getRestTemplate().getForObject(uri, JsonNode.class);
    return response.get("data").get("url").getTextValue();
}
like image 192
Vladimir Filipchenko Avatar answered Nov 17 '22 07:11

Vladimir Filipchenko