我正在尝试通过Google App Engine 提供的App Identity接口使用 Google Drive API。这基本上允许我的 Web 应用程序与 Google 的 API从 server 到 server进行通信。
我不需要我的用户登录,我只需要显示我自己的 Google Drive 文档。
但是,在我设置了所有适当的值和范围,并在控制台页面上启用了所有正确的 Google Drive 旋钮之后,我仍然可以通过一个简单的 GET 请求得到这个https://www.googleapis.com/drive/v2/files
:
{ "error": { "errors": [ { "domain": "usageLimits", "reason": "dailyLimitExceededUnreg", "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.", "extendedHelp": "https://code.google.com/apis/console" } ], "code": 403, "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup." }}
怎么了?我错过了什么?这是实际执行请求的代码 - 有趣的是,如果我使用其他 API(例如 URL 缩短器 API),它会很好地工作:
var scopes = new java.util.ArrayList();
scopes.add("https://www.googleapis.com/auth/drive");
var appIdentity = AppIdentityServiceFactory.getAppIdentityService();
var accessToken = appIdentity.getAccessToken(scopes);
var url = new URL("https://www.googleapis.com/drive/v2/files");
var connection = url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("GET");
connection.addRequestProperty("Content-Type", "application/json");
connection.addRequestProperty("Authorization", "OAuth " + accessToken.getAccessToken());
编辑
例如,如果我只是将 API 更改为使用urlshortner
API,它可以工作:
var url = new URL("https://www.googleapis.com/urlshortener/v1/url/history");
并输出:
{ "kind": "urlshortener#urlHistory", "totalItems": 0, "itemsPerPage": 30}
那么肯定有什么东西不能与 Google Drive 和 App Identity 一起使用?
编辑 2
我在这里的正确答案中找到了一些帮助:https ://stackoverflow.com/a/12526286/50394
但它谈论的是在 Google Apps 上设置客户端 API 范围,我没有使用 Google Apps,我只是使用 Google App Engine 的域foo.appspot.com