我无法访问 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"
}