2011-07-01 6 views
3

나는 오류Google 캘린더 API 및 OAuth를 문제

com.google.gdata.util.AuthenticationException: Unknown authorization header 
    at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600) ~[gdata-core-1.0.jar:na] 
    at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563) ~[gdata-core-1.0.jar:na] 
    at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552) ~[gdata-core-1.0.jar:na] 
    at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530) ~[gdata-core-1.0.jar:na] 
    at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535) ~[gdata-core-1.0.jar:na] 

를 얻을.

오류가 발생하기 전에 다음과 같이하십시오.

1) 나는 구글 인증 :

final AccessTokenResponse response = 
      new GoogleAuthorizationCodeGrant(httpTransport, 
        jsonFactory, 
        clientId, clientSecret, authorizationCode, 
        redirectUrl).execute(); 

final GoogleAccessProtectedResource accessProtectedResource = 
      new GoogleAccessProtectedResource(
        response.accessToken, httpTransport, jsonFactory, 
        clientId, clientSecret, 
        response.refreshToken); 

LOGGER.debug("response.accessToken: {}", response.accessToken); 

this.oauthAccessToken = response.accessToken; 

... 

2) 내가 작업 API를 통해 일부 데이터를 읽어

this.service = 
      new Tasks(httpTransport, accessProtectedResource, 
        jsonFactory); 
    this.service.setApplicationName(this.applicationName); 

이 작동하는 것 같다.

3) 그럼 난 Google 캘린더 API에서 데이터를 읽으려고 : 마지막 줄 (calendarService.getFeed ...) 상기 예외가 발생에서

final OAuthHmacSha1Signer signer = new OAuthHmacSha1Signer(); 

    final GoogleOAuthParameters oauth = new GoogleOAuthParameters(); 

    oauth.setOAuthConsumerKey("myapp.com"); 
    oauth.setOAuthConsumerSecret(CLIENT_SECRET); // Client secret from "Google API access" page, "Client secret" entry 
    oauth.setOAuthToken(this.oauthAccessToken); // Access token from step 1 
    oauth.setOAuthTokenSecret(aAuthorizationCode); 
    // aAuthorizationCode is taken from the callback URL. 
    // For http://myapp.com/oauth2callback?code=4/uy8Arb4bhRPwWYSr3QwKPt9lIZkt 
    // aAuthorizationCode is equal to "4/uy8Arb4bhRPwWYSr3QwKPt9lIZkt" (without quotes) 

    oauth.setScope(SCOPE_CALENDAR); // https://www.google.com/calendar/feeds/ 

    final CalendarService calendarService = 
      new CalendarService(APPLICATION_NAME); 

    calendarService 
      .setOAuthCredentials(oauth, signer); 


    LOGGER.debug("calendarService: {}", calendarService); 

    final URL feedUrl = 
      new URL(
        "http://www.google.com/calendar/feeds/default/allcalendars/full"); 
    final CalendarFeed resultFeed = 
      calendarService.getFeed(feedUrl, CalendarFeed.class); 

.

나는 다음 한 질문 :

1) 내 전화

oauth.setOAuthConsumerKey 

맞습니까?

I. e. Google API 콘솔의 '제품 이름'또는 '클라이언트 ID'입력란 (값은 42912397129473.apps.googleusercontent.com과 같은 값임)

2) setOAuthTokenSecret이 올바른가요? I. e. Google이 사용자를 내 앱으로 다시 리디렉션하면 코드가 생깁니 까?

3) 질문 2와 3에 '예'라고 답한 경우, 그 밖의 원인은 무엇입니까?

감사

드미트리

P. S : 이전에, 나는 간단하게 액세스 할 수있는 구글 캘린더에 액세스 할 수 있습니다 (전. 전자. Google 사용자 이름과 암호). 그러나 내 앱 사용자가 Google 비밀번호를 제공하지 않으므로이 옵션을 사용할 수 없습니다.

답변

0

마지막으로, 미래의 모든 피해자 ^의 OAuth의 W 사용자에게

http://code.google.com/p/gdata-java-client/source/browse/trunk/java/sample/oauth/OAuthExample.java

의 예에 따라 내 조언을 내 문제를 해결하십시오 OAuth는 튜토리얼에서 가장 작은 세부 사항에주의를 기울이십시오. OAuth 악마는 세부 사항에 있습니다.

+0

클라이언트 ID를 반환하는 Google API를 사용하여 애플리케이션을 만든 경우 https://www.google.com/accounts/ManageDomains에서 도메인을 등록해야만 소비자 키를 얻을 수 있습니다. 감사!! – helloworld

+0

@helloworld AFAIR, 예. –