Spring 社交 Facebook 个人资料仅提供 ID 和姓名
Spring social Facebook Profile provides only ID and name
我在使用 spring-social
.
获取 id
和 name
以外的参数时遇到问题
依赖关系:
<!-- 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
方法时,除了 name
和 id
.
之外,所有用户字段都是空的
@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>
我 可以访问 私人 posts
和 likes
用户。在我的 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);
添加 public_profile,在点击 facebook api 时将电子邮件发送到您的范围变量,这肯定会 return 您需要的数据。
我在使用 spring-social
.
id
和 name
以外的参数时遇到问题
依赖关系:
<!-- 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
方法时,除了 name
和 id
.
@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>
我 可以访问 私人 posts
和 likes
用户。在我的 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);
添加 public_profile,在点击 facebook api 时将电子邮件发送到您的范围变量,这肯定会 return 您需要的数据。