Google云端硬盘服务帐户返回403 usageLimits
我正在尝试编写一个AppEngine应用程序,将Google文档写入Google云端硬盘,放入一组特定的文件夹并设置访问权限。 我使用旧的DocsList API,但由于刚刚被弃用,我决定更新我的代码(我还有一些额外的function可以添加)。
我面临的问题是:当我使用服务帐户并尝试冒充特定用户时,即使我没有用完任何配额,我也会获得带有usageLimits的403。
这是我正在使用的代码:
GoogleCredential credentials = new GoogleCredential.Builder() .setTransport(HTTP_TRANSPORT) .setJsonFactory(JSON_FACTORY) .setServiceAccountId("xxxxxxxxxxgserviceaccount.com") .setServiceAccountScopes(DriveScopes.DRIVE) .setServiceAccountPrivateKeyFromP12File( new java.io.File("xxxx-privatekey.p12")) .setServiceAccountUser("user@xxxxxx.org").build();
我使用这些凭据来启动我的Drive对象:
Drive d = Drive.builder(httpTransport, jsonFactory) .setHttpRequestInitializer(credentials) .setJsonHttpRequestInitializer(new JsonHttpRequestInitializer() { @Override public void initialize(JsonHttpRequest request) { DriveRequest driveRequest = (DriveRequest) request; driveRequest.setPrettyPrint(true); } }).setApplicationName("MYAPPNAME").build();
顺便说一句:我尝试过使用新的Drive(….),但无论我尝试什么,这都行不通。 保持抛出错误,找不到内部方法!
回到这个问题:当我使用’d’来调用类似.files()的东西.get(“SOMEFILEID”)。execute()我得到403
{ "code" : 403, "errors" : [ { "domain" : "usageLimits", "message" : "Daily Limit Exceeded. Please sign up", "reason" : "dailyLimitExceededUnreg", "extendedHelp" : "https://code.google.com/apis/console" } ], "message" : "Daily Limit Exceeded. Please sign up" }
我无法弄清楚为什么这不起作用。 我整天都在网上看,但找不到合适的答案。 非常感谢一些帮助。
当API调用缺少Authorization http标头时,我通常会得到403。 跟踪http并查看标题。 “配额”消息的基本原理是,如果没有Auth标头,则您是匿名的,匿名使用的配额为零。
您可能还会检查您的应用是否已为两个Drive API注册,因为我听说这可能会导致同样的问题。
在内部方法问题上,这听起来像你使用不兼容的库版本。 对我来说最有效的方法是删除我用示例代码下载的所有库,然后使用Google Eclipse插件“Google / Add Google APIs …”下载所有最新版本。
所以pinoyyid的回答确实有所帮助,尽管这不是最终答案。
我最终解决了这个问题:
我带了我的AppID(xxxxx.apps.googleusercontent.com)并将其添加到我的CPanel https://www.google.com/a/cpanel/%5B%5BYOURDOMAIN%5D%5D/ManageOauthClients以及这些范围:
- https://www.googleapis.com/auth/drive
- https://www.googleapis.com/auth/drive.file
- https://www.googleapis.com/auth/userinfo.email
- https://www.googleapis.com/auth/userinfo.profile
之后,我可以对Drive环境进行身份validation请求。 现在遇到一堆不同的问题但403已经解决了。