0
我是Spring Social的新手。我正在研究Java Spring社交應用程序,我希望能夠通過Facebook註冊。任何人都可以請示例來實現它嗎?如何使用Spring Social通過Facebook註冊
在Spring控制器回調方法
@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;
}
在上述方法中我得到的所有參數(如電子郵件,第一個名字,約等)作爲空
你試過的代碼在哪裏? – Sachith