在Grails应用程序中,使用spring security facebook插件,当用户登录时,应用程序如何获得实际的facebook用户名,以便主页可以显示登录的用户名?
The plugin provides Facebook API access_token
, and you have to request such user details from Facebook.
Example:
Add dependency to Spring Social Facebook:
dependency {
compile 'org.springframework.social:spring-social-core:1.0.1.RELEASE'
compile 'org.springframework.social:spring-social-facebook:1.0.1.RELEASE'
}
and then load it from Facebook on user creation, by adding following into FacebookAuthService:
void onCreate(FacebookUser user, FacebookAuthToken token) {
Facebook facebook = new FacebookTemplate(token.accessToken.accessToken)
FacebookProfile fbProfile = facebook.userOperations().userProfile
//fill the name
//fieldname ('fullname' at this example) is up to you
user.fullname = fbProfile.name
}
See also
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.