【问题标题】:How do I use the Google drive API key to access drive content from android application?如何使用 Google 驱动器 API 密钥从 android 应用程序访问驱动器内容?
【发布时间】:2012-11-16 07:22:25
【问题描述】:

我无法访问 Google 云端硬盘。我在 Google API 控制台中创建了一个 API KEY 并启用了 Google Drive API 和 SDK。我在代码中的哪里设置 API KEY?

驱动器构建器没有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"
 }

【问题讨论】:

标签: android google-drive-api google-drive-realtime-api


【解决方案1】:

您需要在 API 控制台中激活两件事: - 驱动 API - 驱动SDK

很多人只激活一个。

此外,在发布最终应用程序之前,不要忘记添加您的真实证书 SHA1。

有类似的答案: Google Drive SDK Exception

【讨论】:

  • 在从 Google Play 服务获取“内部错误”并重新调整 API 控制台设置一整天之后,至少我已经阅读了这条评论......谢谢,伙计!
【解决方案2】:

在 Android 中,按照 pommedeterresautee 的规定,我们需要激活 Drive API 和 Drive SDK,然后激活 API Key。

这必须在应用程序标签内的 Android 清单中设置,并与其他应用程序组件标签一样:

<application...>
<activity ...>
<meta-data
        android:name="com.google.android.apps.drive.APP_ID"
        android:value="id=YOUR_API_KEY" />
</application>

执行此操作后,您将能够访问 api 而不会出现 403“访问未配置”问题。

【讨论】:

    猜你喜欢
    • 2014-12-13
    • 2016-09-21
    • 1970-01-01
    • 1970-01-01
    • 2015-10-30
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    相关资源
    最近更新 更多