2012-01-25 10 views
0

Facebookのアプリを開発しようとしています。私はFacebookのコントローラを作成し、connectionFactoryオブジェクトを作成し、oAuth oprationsとaccessgrantオブジェクトを取得しました。私はまた、アクセストークンを得た。しかし、私は、接続FacebookConnectionFactory connection "https://graph.facebook.com/me"のGETリクエストで400(Bad Request)が発生しましたMissingAuthorizationException:

Connection<Facebook> connection = connectionFactory.createConnection(accessGrant); 

を作成しようとしたら、私はエラーを取得しています:

MissingAuthorizationException:認証が動作のために必要とされるが、APIバインディングが許可なしに作成されたが。

のフルスタックトレース:

 
[1/25/12 9:18:17:097 IST] 0000001a SystemOut  O oauthOperations :org[email protected]46714671 
[1/25/12 9:18:17:097 IST] 0000001a SystemOut  O authorizeUrl :https://graph.facebook.com/oauth/authorize?client_id=xxxxx&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A80%2FSpringSocial%2Fstart&scope=read_stream%2Cemail%2Cpublish_stream%2Coffline_access 
[1/25/12 9:19:15:930 IST] 0000001a SystemOut  O oauthOperations authorizationCode :org[email protected]46714671 
[1/25/12 9:19:25:197 IST] 0000001a SystemOut  O accssTokentemp :xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
[1/25/12 9:19:35:541 IST] 0000001a SystemOut  O facebook :[email protected]c221c2 
[1/25/12 9:19:35:994 IST] 0000001a RestTemplate W org.springframework.web.client.RestTemplate handleResponseError GET request for "https://graph.facebook.com/me" resulted in 400 (Bad Request); invoking error handler 
[1/25/12 9:19:36:041 IST] 0000001a servlet  E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: Uncaught exception created in one of the service methods of the servlet SpringSocial in application SpringSocialFacebookEar. Exception created : org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.social.MissingAuthorizationException: Authorization is required for the operation, but the API binding was created without authorization. 
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:681) 
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:574) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:718) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:831) 
    at com.ibm.ws.cache.servlet.ServletWrapper.serviceProxied(ServletWrapper.java:307) 
    at com.ibm.ws.cache.servlet.CacheHook.handleFragment(CacheHook.java:579) 
    at com.ibm.ws.cache.servlet.CacheHook.handleServlet(CacheHook.java:250) 
    at com.ibm.ws.cache.servlet.ServletWrapper.service(ServletWrapper.java:259) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1663) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:939) 

Caused by: org.springframework.social.MissingAuthorizationException: Authorization is required for the operation, but the API binding was created without authorization. 
    at org.springframework.social.facebook.api.impl.FacebookErrorHandler.handleFacebookError(FacebookErrorHandler.java:95) 
    at org.springframework.social.facebook.api.impl.FacebookErrorHandler.handleError(FacebookErrorHandler.java:60) 
    at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:486) 
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:443) 
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:415) 
    at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:213) 
    at org.springframework.social.facebook.api.impl.FacebookTemplate.fetchObject(FacebookTemplate.java:165) 
    at org.springframework.social.facebook.api.impl.UserTemplate.getUserProfile(UserTemplate.java:50) 
    at org.springframework.social.facebook.api.impl.UserTemplate.getUserProfile(UserTemplate.java:46) 
    at org.springframework.social.facebook.connect.FacebookAdapter.setConnectionValues(FacebookAdapter.java:42) 
    at org.springframework.social.facebook.connect.FacebookAdapter.setConnectionValues(FacebookAdapter.java:30) 
    at org.springframework.social.connect.support.AbstractConnection.setValues(AbstractConnection.java:172) 
    at org.springframework.social.connect.support.AbstractConnection.initKey(AbstractConnection.java:135) 
    at org.springframework.social.connect.support.OAuth2Connection.(OAuth2Connection.java:73) 
    at org.springframework.social.connect.support.OAuth2ConnectionFactory.createConnection(OAuth2ConnectionFactory.java:58) 
    at com.tgt.social.controller.FaceBookConnectController.facebookConnect(FaceBookConnectController.java:107) 

私のコントローラクラス:

@Controller 
public class FaceBookConnectController { 

    private static OAuth2Operations oauthOperations = null; 
    private static FacebookConnectionFactory connectionFactory = null; 
    private static OAuth2Parameters params = null; 

    @RequestMapping("/start") 
    public ModelAndView facebookConnect(Model model,HttpServletRequest request,HttpServletResponse response) { 
     Security.setProperty("ssl.SocketFactory.provider", "com.ibm.jsse2.SSLSocketFactoryImpl"); 
     Security.setProperty("ssl.ServerSocketFactory.provider", "com.ibm.jsse2.SSLServerSocketFactoryImpl"); 
     System.setProperty("https.proxyHost", "localhost"); 
     System.setProperty("https.proxyPort", "8888"); 

     String clientId = "xxxxxxxxx"; 
     String clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxx"; 
     String redirectUrl = "http://localhost:80/SpringSocial/start"; 

     try { 
      String authorizationCode = request.getParameter("code"); 
      if(null != authorizationCode){ 
       MultiValueMap paramsMap1 = new LinkedMultiValueMap(); 
       System.out.println("oauthOperations authorizationCode :"+oauthOperations); 
       //paramsMap.set("client_id", clientId); 
       //paramsMap.set("client_secret", clientSecret); 
       //paramsMap.set("code", authorizationCode); 
       paramsMap1.set("redirect_uri", redirectUrl); 
       paramsMap1.set("grant_type", "authorization_code"); 
       paramsMap1.set("scope","read_stream,user_about_me,user_birthday,user_likes,user_status,email,publish_stream,offline_access"); 
       //AccessGrant accessGrant = oauthOperations.exchangeForAccess(authorizationCode, redirectUrl, paramsMap1); 
       System.out.println("connectionFactory authorizationCode :"+connectionFactory); 
       AccessGrant accessGrant = connectionFactory.getOAuthOperations().exchangeForAccess(authorizationCode, redirectUrl, paramsMap1); 
       String accssTokentemp = accessGrant.getAccessToken(); 
       System.out.println("accssTokentemp :"+accssTokentemp); 
       String scope_p = accessGrant.getScope(); 
       System.out.println("scope_p :"+scope_p); 
       Facebook facebook = new FacebookTemplate(accssTokentemp); 
       System.out.println("facebook :"+facebook); 
       Connection<Facebook> connection = connectionFactory.createConnection(accessGrant); 
       //FacebookProfile userProfile = facebook.userOperations().getUserProfile(); 
       System.out.println("connection :"+connection); 

      }else{ 
       MultiValueMap paramsMap = new LinkedMultiValueMap(); 
       connectionFactory = new FacebookConnectionFactory(clientId,clientSecret); 
       System.out.println("connectionFactory :"+connectionFactory); 
       oauthOperations = connectionFactory.getOAuthOperations(); 
       params = new OAuth2Parameters(); 
       params.setRedirectUri(redirectUrl); 
       params.setScope("read_stream,user_about_me,user_birthday,user_likes,user_status,email,publish_stream,offline_access"); 
       paramsMap.set("client_id", clientId); 
       paramsMap.set("client_secret", clientSecret); 
       paramsMap.set("code", authorizationCode); 
       paramsMap.set("redirect_uri", redirectUrl); 
       paramsMap.set("grant_type", "authorization_code"); 
       System.out.println("oauthOperations :"+oauthOperations); 
       String authorizeUrl = oauthOperations.buildAuthorizeUrl(GrantType.AUTHORIZATION_CODE, params); 
       System.out.println("authorizeUrl :"+authorizeUrl); 
       response.sendRedirect(authorizeUrl); 
      } 

     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

     return null; 
    } 
} 

私はここで間違っているものを教えてください? インスタンス化がconnectionFactoryオブジェクトに対して正しくないかどうか。

+0

それを使用API:facebook.isAuthorized()。これはtrueを返します – denzal

答えて

1

あなたがもしあれば、社会的試行は、ユーザーのすでに確立された接続を検索するため、usersConnectionRepositoryにaddConnectionする必要があり、それが認可を取得しようとauthorized.Iが試みとして、私は取得していますFacebookのオブジェクトが表示されている

関連する問題