这是我将URl重定向到facebook
String uri = "";
FacebookConnectionFactory connectionFactory = new FacebookConnectionFactory(MCRUtil.getMcrResourceBundle().getString("facebook.clientId"), MCRUtil.getMcrResourceBundle()
.getString("facebook.clientSecret"));
OAuth2Operations oauthOperations = connectionFactory.getOAuthOperations();
OAuth2Parameters params = new OAuth2Parameters();
String param = request.getParameter("param");
if (param.equalsIgnoreCase("signUp")) {
uri = redirectUri + "fbSignUp.htm";
} else if (param.equalsIgnoreCase("friend")) {
uri = redirectUri + "m-auth-fbfriends.htm";
}
params.setRedirectUri(uri);
params.setScope("email,user_about_me,user_birthday,user_likes,user_status,publish_stream,friends_about_me,publish_actions,read_friendlists");
params.setScope("email");
params.set("display", "popup");
String authorizeUrl = oauthOperations.buildAuthorizeUrl(GrantType.AUTHORIZATION_CODE, params);
return "redirect:" + authorizeUrl;
我正在使用facebookconnectionfactory
此代码将重定向到facebook登录,然后我想将用户详细信息存储在我的数据库中。所以重定向另一个服务在下面
String facebookAccessToken = request.getParameter("code");
if (facebookAccessToken == null) {
return "socialError";
}
UserVO customer = null;
AccessGrant accessGrant = null;
/* By using clientId and secret getting connection facotiry */
FacebookConnectionFactory connectionFactory = new FacebookConnectionFactory(MCRUtil.getMcrResourceBundle().getString("facebook.clientId"), MCRUtil.getMcrResourceBundle()
.getString("facebook.clientSecret"));
String uri = redirectUri + "fbSignUp.htm";
OAuth2Operations oauthOperations=connectionFactory.getOAuthOperations();
accessGrant = oauthOperations.exchangeForAccess(facebookAccessToken, uri,null);
Connection<Facebook> connection = connectionFactory.createConnection(accessGrant);
Facebook facebook = connection.getApi();
FacebookProfile userProfile = facebook.userOperations().getUserProfile();
UserVO userVO = new UserVO();
userVO.setEmail(userProfile.getEmail());
userVO.setFirstName(userProfile.getFirstName());
userVO.setLastName(userProfile.getLastName());
这里我得到accessGrant null数据.. accessGrant = oauthOperations.exchangeForAccess(facebookAccessToken,uri,null); ..我正在使用spring-social-core-1.1.0 jar你可以帮助我如何获得accessGrant值......
提前致谢