我是Spring Social的新手。我正在研究java Spring Social应用程序,我希望能够通过facebook注册。任何人都可以用例子来回应它吗?
在Spring Controller回调方法
中@RequestMapping(value = "/callback", method = RequestMethod.GET)
@ResponseBody
public String postOnWall(@RequestParam("code") String code,
@RequestParam("state") String state, HttpServletRequest request,
HttpServletResponse response) throws Exception {
System.out.println("hi welcome to callback method");
OAuthService oAuthService = facebookServiceProvider.getService();
Verifier verifier = new Verifier(code);
Token accessToken = oAuthService
.getAccessToken(Token.empty(), verifier);
// Token accessToken = new Token("EAADOe1JXBWgBAJVtLpGKTM6pol0n8r8fZAHnEPmNZCnId9419k9EHj2scdtcZBotMW5oYneKTvY93ZASRpeUGLiXRKhWvuZBA3zfEgIjGpvLMZCzODvA3SuNm9glARg0c5puZARVuTyZAiSqibD76taIUk06O08lOSm2vJDufCAlUdIP8P9c4ZBLP", "", "");
System.out.println("accessToken "+accessToken);
FacebookTemplate template = new FacebookTemplate(accessToken.getToken());
System.out.println(template.isAuthorized()+" autherized or not condition");
FacebookProfile facebookProfile = template.userOperations()
.getUserProfile();
System.out.println("user permissions "+template.userOperations().getUserPermissions());
String userId = facebookProfile.getId();
System.out.println("user about "+facebookProfile.getAbout());
LOGGER.info("Logged in User Id : {}", userId);
MultiValueMap<String, Object> map = facebookUtil
.publishLinkWithVisiblityRestriction(state);
try {
template.publish(facebookProfile.getId(), "feed", map);
} catch (Exception ex) {
LOGGER.error(
"Exception Occurred while posting a link on facebook for user Id : {}, exception is : {}",
userId, ex);
return PUBLISH_ERROR;
}
return PUBLISH_SUCCESS;
}
在上面的方法中,我得到所有参数(如电子邮件,名字,等等)为null