小编use*_*780的帖子

如何使用Google Drive API密钥从Android应用程序访问驱动器内容?

我无法访问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();
}
Run Code Online (Sandbox Code Playgroud)

获得:

 com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
 {
   "code" : 403,
   "errors" : [ {
     "domain" : "usageLimits",
     "message" : "Access Not Configured",
     "reason" : "accessNotConfigured"
  } ],
  "message" : "Access Not Configured"
 }
Run Code Online (Sandbox Code Playgroud)

android google-drive-api google-drive-realtime-api

2
推荐指数
1
解决办法
1万
查看次数