简体   繁体   English

Grails Facebook使用spring security登录 - 如何知道登录的用户名

[英]Grails Facebook Login using spring security - how to know logged in user name

在Grails应用程序中,使用spring security facebook插件,当用户登录时,应用程序如何获得实际的facebook用户名,以便主页可以显示登录的用户名?

The plugin provides Facebook API access_token , and you have to request such user details from Facebook. 该插件提供Facebook API access_token ,您必须从Facebook请求此类用户详细信息。

Example: 例:

Add dependency to Spring Social Facebook: 添加对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: 然后通过在FacebookAuthService中添加以下内容,在用户创建时从Facebook加载它:

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 也可以看看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM