gpt4 book ai didi

facebook - Grails Facebook 使用 Spring Security 登录 - 如何知道登录的用户名

转载 作者:行者123 更新时间:2023-12-02 19:11:45 26 4
gpt4 key购买 nike

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

最佳答案

该插件提供 Facebook API access_token,您必须向 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'
}

然后在用户创建时通过将以下内容添加到 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
}

另请参阅

关于facebook - Grails Facebook 使用 Spring Security 登录 - 如何知道登录的用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15151717/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com