【发布时间】:2014-06-06 14:14:20
【问题描述】:
我需要在我的 GAE 应用程序中初始化 Drive Service。我正在使用带有 3 条腿的 OAuth 2.0。我使用常规 Google 帐户(无服务帐户)。我正在尝试:
GoogleCredential credentials = usuarioService.getGoogleCredentials();
Drive service = new Drive.Builder(TRANSPORT, JSON_FACTORY, credentials).build();
我得到这个错误:
Caused by: java.lang.NoSuchFieldError: MAJOR_VERSION
at com.google.api.services.drive.Drive.<clinit>(Drive.java:48)
at com.google.api.services.drive.Drive$Builder.build(Drive.java:8243)
OAuth 2.0 流授权正在运行,但访问云端硬盘时出现上述错误。
我认为我的 GoogleCredentials 没有错误,因为我使用相同的方法来获得授权以使用 Google Picker。
我从用户那里获取 GoogleCredential 的方式是:
GoogleCredential credentials = new GoogleCredential.Builder()
.setClientSecrets(clientId, clientSecret)
.setJsonFactory(JSON_FACTORY)
.setTransport(HTTP_TRANSPORT)
.build()
.setRefreshToken(user.getOAuth2RefreshToken())
.setAccessToken(user.getOAuth2AccessToken()); //previous Access Token
你能帮帮我吗?
迭戈。
更新 我已将云端硬盘库更新为 the last one (v2) 和 google-api-client 1.18,但它仍然无法正常工作。
现在我收到此错误:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.google.api.services.drive.Drive
更新 2 考虑到我在重建 GoogleCredential 对象时做错了什么,当我从授权流程请求原始凭据时,我尝试调用 Drive.Builder():
final GoogleTokenResponse response = flow.newTokenRequest(authCode).setRedirectUri(callback).execute();
Credential credential = flow.createAndStoreCredential(response, null);
// Calling to Drive Service
Drive service = new Drive.Builder(httpTransport, jsonFactory, credential).build();
我得到同样的错误:
Caused by: java.lang.NoSuchFieldError: MAJOR_VERSION
我对日历做同样的事情,我得到同样的错误
我正在使用下一个库: google-api-client 1.18
google-api-client-servlet 1.18
google-api-service-drive-v2-1.18
google-http-client 1.18
google-http-client-jackson 1.18
google-oauth-client 1.18
【问题讨论】:
-
您是否在 GAE 中开启了 Drive API? console.developers.google.com/project
-
它已打开@jedison,顺便说一句,我正在使用 Eclipse 进行本地工作。
-
并且您已为该项目启用了 Drive SDK:“Drive SDK 在此项目上未激活”。 code.google.com/apis/console/b/0/…>
-
是的。我的应用程序中有不同的用户。组和个人用户。我将服务帐户和 OAuth 1.0 与组一起使用,并且它正在工作。我无法对个人用户使用 SA,我使用的是 OAuth 2.0 并且无法正常工作。
-
你和 drEdit 样本比较过吗?
标签: google-app-engine oauth-2.0 google-api google-drive-api google-api-client