In the blog we have seen how we can connect with Facebook using grails oauth plugin. Using that blog we can get various information of the user but not profile image.

To get the Facebook profile image you require to make one more request, like:

def facebook() {
 Token facebookAccessToken = (Token) session[oauthService.findSessionKeyForAccessToken('facebook')]
 ...
 def profileImageApiUrl = grailsApplication.config.grails.facebookProfileImage.api.url
 def facebookResource = oauthService.getFacebookResource(facebookAccessToken, profileImageApiUrl)
 def facebookResponse = JSON.parse(facebookResource?.getBody())
 def profileImageUrl = facebookResponse.data?.url
 ... 
}

where grails.facebookProfileImage.api.url = “https://graph.facebook.com/me/picture?type=large&redirect=false

NOTE:-redirect=false” is mandatory otherwise you got response something like:
{Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={“FACEBOOK_NON_JSON_RESULT”:”����u0000u0010JFIFu0000u0001u0002u0000u0000u0001u0000u0001u0000u0000��u00006Photoshop”}}, error: null, isFromCache:false}


I have deployed Grails Oauth Plugin Demo project in Heroku.

See this project in action (DEMO).


Hope this helps 🙂 .