gpt4 book ai didi

facebook - Grails Facebook Spring Security返回null

转载 作者:行者123 更新时间:2023-12-02 14:50:16 24 4
gpt4 key购买 nike

我正在使用与“:spring-security-core:2.0-RC5 ”集成的“:spring-security-facebook:0.17 ”。
我已实现 facebookAuthService.groovy 进行自定义。但是 token 未通过身份验证,并且fbProfile返回的null除外,除了id和name。

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
FacebookProfile fbProfile2 = facebook.userOperations().getUserProfile()
def ff = facebook.userOperations().userPermissions
String email = fbProfile.email
String username = fbProfile.username
String firstName = fbProfile.firstName
String lastName = fbProfile.lastName

println fbProfile as JSON
println token as JSON
println fbProfile.email

User person = new User(
username: 'jgf',
password: token.accessToken.accessToken, //not really necessary
enabled: true,
accountExpired: false,
accountLocked: false,
passwordExpired: false,

//fill with data loaded from Facebook API
email: email
)
person.save(failOnError: true)
UserRole.create(person, AuthRole.findByAuthority('ROLE_USER'))
UserRole.create(person, AuthRole.findByAuthority('ROLE_FACEBOOK'))
FacebookUser fbUser = new FacebookUser(
uid: token.uid,
accessToken: token.accessToken.accessToken,
accessTokenExpires: token.accessToken.expireAt,
user: person
)
fbUser.save(failOnError: true)
return fbUser
}

响应如下:
访问 token :

{"accessToken":{"accessToken":"CAAHt52DpmkIBAH34zFdy0PZC3a9y3JZARvfrVckTHN9xMZCOgL6QHzxNIna07ZBa5ZBXw2BZCwyflvCIIkPzn3pNk8QHFNqZCts8tAHZB1wK4AEJZBEPNHqFRWssPZBuIOCa6vk7U5W3K0ilIZB7GWx0MJCZC7UBy5mhb5W5RLkZB1wTn09Qs4NIGU9KDi22OPWbpEKQJoERr9fSfJwZDZD","expireAt":"2016-02-01T06:58:46Z"},"authenticated":false,"authorities":[],"code":"AQD3IrrusGkBsF91yaD68T81S4s-TO4qG17DARQepzB-y2q4vmWSFkoTmMX_ObJHjbOg83YcSE0DwsNjvKS7U2JH_O2C6XjVGM5vG8ZvxpXTo57RFhAzvTxd0NMIVL4Qypto2VRDcLeNIIW8dCQHNqhzJ-0l3_4BQfHk4ygXFEBFTmZA6wkFspnLr9awL5qL8t0m6h5AZbkydM6KhQCYmL_xmy8Evl22NSjYRG-G-edjVNo4t4Fn9AQt7AXEjG_xjytdUoBPa0Zpl5AGM1-VpeYOvhKDPGvXQ3fFkS-8oSe8dyj1T6gAc8BG2yQ4bycPftVqfNt3uCGpesYIkI-dnwxd","credentials":1026180034068785,"details":null,"name":"","principal":null,"redirectUri":"http://localhost:8080/j_spring_security_facebook_check","uid":1026180034068785}



和fbProfile:

{"about":null,"bio":null,"birthday":null,"class":"org.springframework.social.facebook.api.FacebookProfile","education":null,"email":null,"favoriteAtheletes":null,"favoriteTeams":null,"firstName":null,"gender":null,"hometown":null,"id":"1026180034068785","inspirationalPeople":null,"interestedIn":null,"languages":null,"lastName":null,"link":null,"locale":null,"location":null,"middleName":null,"name":"Sanjib Maharjan","political":null,"quotes":null,"relationshipStatus":null,"religion":null,"significantOther":null,"sports":null,"thirdPartyId":null,"timezone":null,"updatedTime":null,"username":null,"website":null,"work":null}



这里的问题是一切都为空,我不知道为什么。

PS :所有facebook凭证都是正确的,并且还提供了权限(public_profile,email和user_about_me)。
是因为 token 未通过身份验证,或者我缺少其他东西。感谢您的帮助。谢谢。

最佳答案

我终于弄清楚了为什么除了名称和ID之外其他所有内容都是空的。

自2015年7月8日起,Facebook已更改了api-API版本2.4: https://developers.facebook.com/docs/apps/changelog#v2_4

并据此指定您要返回的每个字段和边,例如

https://graph.facebook.com/me?access_token=kjhgfgfhgghjhghj&fields=id,name,email,firstname



facebook.userOperations()。getUserProfile()提供了ID和name以外的空字段,因此解决方案是使用允许设置字段的其他api,或者我们可以通过点击uri( https://graph.facebook.com/me?access_token=kjhgfgfhgghjhghj&fields=id,name,email,firstname)手动进行设置。

关于facebook - Grails Facebook Spring Security返回null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34063833/

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