Google Calendar 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] 

尝试通过API访问Google日历数据时。

以下是该错误之前发生的事情。

1)我通过Googlevalidation:

 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 Calendar API中读取数据:

  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); 

在最后一行(calendarService.getFeed …)发生上述exception。

我有以下问题:

1)是我的电话

 oauth.setOAuthConsumerKey 

正确?

I. e。 是“消费者密钥”,等同于Google API控制台中的“产品名称”,或“客户端ID”字段(值类似于42912397129473.apps.googleusercontent.com)

2)setOAuthTokenSecret是否正确? I. e。 当Google将用户重定向回我的应用时,我得到的代码是什么?

3)如果问题2和3的回答是肯定的,那还有什么可能是我的问题的原因?

谢谢

德米特里

PS:以前,我可以通过简单访问(即使用Google用户名和密码)访问Google日历。 但是,现在这不是一个选项,因为我的应用的用户不想放弃他们的Google密码。

最后,我通过以下示例解决了我的问题

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

我对所有未来受害者的建议^ OAuth的用户:注意OAuth教程中的最小细节。 OAuth恶魔在于细节。