gpt4 book ai didi

java - Spring 社交 Facebook 个人资料仅提供 ID 和姓名

转载 作者:行者123 更新时间:2023-12-01 08:52:53 30 4
gpt4 key购买 nike

我在使用 spring-social 获取 idname 以外的参数时遇到问题。

依赖关系:

    <!-- Spring Social -->
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-config</artifactId>
<version>1.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-core</artifactId>
<version>1.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-security</artifactId>
<version>1.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-web</artifactId>
<version>1.1.2.RELEASE</version>
</dependency>

<!-- Spring Social Facebook -->
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-facebook</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>

配置:

<security:http ...>
...
<security:custom-filter before="PRE_AUTH_FILTER" ref="socialAuthenticationFilter" />
...
</security:http>
<security:authentication-manager alias="authenticationManager">
...
<security:authentication-provider ref="socialAuthenticationProvider" />
</security:authentication-manager>
<bean id="socialAuthenticationProvider" class="org.springframework.social.security.SocialAuthenticationProvider">
<constructor-arg ref="inMemoryUsersConnectionRepository"/>
<constructor-arg ref="socialUserDetailsService"/>
</bean>

<bean id="inMemoryUsersConnectionRepository"
class="org.springframework.social.connect.mem.InMemoryUsersConnectionRepository">
<constructor-arg name="connectionFactoryLocator" ref="connectionFactoryLocator"/>
<property name="connectionSignUp" ref="connectionSignUp"/>
</bean>

<bean id="connectionFactoryLocator"
class="org.springframework.social.security.SocialAuthenticationServiceRegistry">
<property name="authenticationServices">
<list>
<ref bean="facebookAuthenticationService"/>
</list>
</property>
</bean>

<bean id="socialAuthenticationFilter" class="org.springframework.social.security.SocialAuthenticationFilter">
<constructor-arg name="authManager" ref="authenticationManager"/>
<constructor-arg name="userIdSource" ref="userIdSource"/>
<constructor-arg name="usersConnectionRepository" ref="inMemoryUsersConnectionRepository"/>
<constructor-arg name="authServiceLocator" ref="connectionFactoryLocator"/>
<property name="authenticationSuccessHandler" ref="loginGuidAuthenticationSuccessHandler"/>
</bean>

<bean id="userIdSource" class="org.springframework.social.security.AuthenticationNameUserIdSource"/>

<bean id="facebookAuthenticationService"
class="org.springframework.social.facebook.security.FacebookAuthenticationService">
<constructor-arg name="apiKey" value="<myKey>"/>
<constructor-arg name="appSecret" value="<mySecret>"/>
<property name="defaultScope" value="email"/>
</bean>

<bean id="connectionSignUp" class="my.package.DefaultConnectionSignUp"/>

我有自己的一些所需服务的实现,但我认为这些服务不相关。当我在 ConnectionSignUp 的实现中调试 execute 方法时,除了 nameid 之外,所有用户字段均为空.

@Override
public String execute(Connection<?> connection) {
Connection<Facebook> fbConnection = (Connection<Facebook>) connection;
fbConnection.getApi().userOperations().getUserProfile().getEmail(); //null
fbConnection.getApi().userOperations().getUserProfile().getFirstName(); //null
fbConnection.fetchUserProfile().getEmail(); //null
fbConnection.fetchObject("me", User.class); //email == null
...
}

我的jsp表单:

    <form name='facebookSocialloginForm'
action="<c:url value='/auth/facebook' />" method='POST'>
<input type="hidden" name="scope"
value="public_profile,email,user_about_me,user_birthday,user_likes"/>
...
</form>

不过,我可以访问用户的私有(private)帖子喜欢。我的 Facebook 帐户上显示该应用程序可以访问电子邮件和其他信息。

有什么建议吗?如果我错过了一些重要的内容,请询问,我将提供更多信息。

最佳答案

Facebook API 的更改可能导致此问题。尝试下面的代码:

UserOperations userOperations = facebook.userOperations();
String [] fields = { "id", "email", "first_name", "last_name" };
org.springframework.social.facebook.api.User profile = facebook.fetchObject
("me", org.springframework.social.facebook.api.User.class, fields);

关于java - Spring 社交 Facebook 个人资料仅提供 ID 和姓名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42273470/

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