2012-11-16 112 views
2

我无法访问Google驱动器。我在Google API控制台中创建了一个API KEY,并启用了Google Drive API和SDK。我在哪里设置代码中的API KEY?如何使用Google驱动器API密钥从Android应用程序访问驱动器内容?

驱动器生成器没有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" 
} 
+0

我遇到同样的问题:http://stackoverflow.com/questions/13462952/google-drive-sdk-exception。你有没有能够解决这个问题? –

回答

5

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

很多人只激活一个。

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

有这种类似的答案: Google Drive SDK Exception

+0

经过整天得到Google Play服务的“内部错误”并重新调整API控制台设置,至少我已阅读此评论......谢谢,男士! –

2

在Android中,如pommedeterresautee指定了需要执行两个驱动API和驱动SDK,然后导致API密钥激活。

这在Android清单中设置的应用程序标签中,并与其他应用程序组件的标签,看齐:

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

当你做到这一点,你就可以不用403访问API “访问未配置”问题。

相关问题