は、私はエラー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のようなもの)に等しい「コンシューマキー」です。012)2)setOAuthTokenSecretは正しいですか?
I. Googleがユーザーを自分のアプリにリダイレクトするとき、それは私が取得するコードですか?
3)質問2と3に「はい」と回答した場合、他に何が問題の原因になりますか?
おかげ
ドミトリ
P. S:以前、私は簡単なアクセスをGoogleカレンダーにアクセスすることができ(すなわち、Googleのユーザー名とパスワードを使用して)。しかし、私のアプリのユーザーは自分のGoogleパスワードを譲りたくないので、これは今選択できません。
クライアントIDを返すGoogle APIを使用してアプリケーションを作成する場合は、https://www.google.com/accounts/ManageDomainsでドメインを登録してコンシューマーキーを取得する必要がありますか?ありがとう! – helloworld
@helloworld AFAIR、はい。 –