2016-11-28 9 views
0

私は春の社会に新しいです。私はFacebookに登録できるようにしたいと思っているJava Spring Socialアプリケーションに取り組んでいます。誰もそれを達成するための例で応答してもらえますか?上記の方法では春の社会を使ってFacebookに登録する方法

春コントローラのコールバックメソッドで

@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; 
    } 

私はヌル

+1

あなたの試したコードはどこですか? – Sachith

答えて

関連する問題