I am building my first grails app and have successfully integrated all of the following plugins:
Currently, I can click a "Login with Facebook" button and I've added a FacebookAuthService which allows me to fetch username, e-mail, etc. and I am displaying the username to the screen using the "sec" taglib. My question is regarding how to fetch the user's Facebook Profile Picture and display it to the page. I've looked all over and couldn't find a good example. Can anyone provide one?
I have the following method defined in FacebookAuthService:
FacebookUser create(FacebookAuthToken token) {
log.info("Create domain for facebook user $token.uid")
//Use Spring Social Facebook to load details for current user from Facebook API
Facebook facebook = new FacebookTemplate(token.accessToken.accessToken)
FacebookProfile fbProfile = facebook.userOperations().userProfile
String email = fbProfile.email
String username = fbProfile.username
String firstName = fbProfile.firstName
String lastName = fbProfile.lastName
User person = new User(
username: [firstName, lastName].join(' '),
password: token.accessToken.accessToken, //not really necessary
enabled: true,
accountExpired: false,
accountLocked: false,
passwordExpired: false,
//fill with data loaded from Facebook API
name: [firstName, lastName].join(' '),
email: email
)
person.save( flush : true)
person.validate()
println person.errors
UserRole.create(person, Role.findByAuthority('ROLE_USER'))
UserRole.create(person, Role.findByAuthority('ROLE_FACEBOOK'))
FacebookUser fbUser = new FacebookUser(
uid: token.uid,
accessToken: token.accessToken.accessToken,
accessTokenExpires: token.accessToken.expireAt,
user: person
)
fbUser.save()
return fbUser
}