我无法访问 Google 云端硬盘。我在 Google API 控制台中创建了一个 API KEY 并启用了 Google Drive API 和 SDK。我应该在代码中的什么地方设置 API KEY?
Drive builder 没有 setJsonHttpRequestInitializer
方法。我在哪里可以设置 KEY?有其他选择吗?
private Drive getDriveService(String token) {
HttpTransport ht = AndroidHttp.newCompatibleTransport();
JacksonFactory jsonFactory = new JacksonFactory();
Credential credentials = new GoogleCredential().setAccessToken(token);
Drive.Builder b = new Drive.Builder(ht, jsonFactory, credentials);
b.setHttpRequestInitializer(credentials);
return b.build();
}
获得:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "usageLimits",
"message" : "Access Not Configured",
"reason" : "accessNotConfigured"
} ],
"message" : "Access Not Configured"
}
最佳答案
您需要在 API 控制台中激活两件事: - 驱动API - 驱动SDK
很多人只激活一个。
此外,在发布最终应用程序之前,不要忘记添加您的真实证书 SHA1。
有一个类似的答案: Google Drive SDK Exception
关于android - 如何使用 Google 驱动器 API key 从 Android 应用程序访问驱动器内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13412134/