Google云端硬盘服务帐户返回403 usageLimits

时间:2012-09-19 21:51:23

标签: java google-app-engine oauth-2.0 google-drive-api

我正在尝试编写一个将Google文档写入Google云端硬盘的AppEngine应用,放入一组特定的文件夹并设置访问权限。我有这个使用旧的DocsList API,但由于刚刚被弃用,我决定更新我的代码(我还有一些额外的功能可以添加)。

我面临的问题是:当我使用服务帐户并尝试冒充特定用户时,即使我没有用完任何配额,我也会获得带有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();

顺便说一句:我尝试过使用新的驱动程序(....),但无论我尝试什么,这都行不通。继续抛出未找到内部方法的错误!

回到这个问题: 当我使用'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"
}

我无法弄清楚为什么这不起作用。我整天都在网上看,但找不到合适的答案。非常感谢一些帮助。

2 个答案:

答案 0 :(得分:2)

所以pinoyyid的回答确实有所帮助,尽管这不是明确的答案。

我最终解决了这个问题:

我带了我的AppID(xxxxx.apps.googleusercontent.com),并将其添加到我的CPanel https://www.google.com/a/cpanel/ [|YDODAIN] ]/ManageOauthClients 有这些范围:

之后,我可以对Drive环境进行身份验证请求。现在遇到一堆不同的问题但403已经解决了。

答案 1 :(得分:1)

当API调用缺少Authorization http标头时,我通常会得到403。跟踪http并查看标题。 “配额”消息的基本原理是,如果没有Auth标头,则您是匿名的,匿名使用的配额为零。

您可能还会检查您的应用是否已为两个云端硬盘API注册,因为我听说这可能会导致同样的问题。

在内部方法问题上,这听起来像是在使用不兼容的库版本。最适合我的是删除我用示例代码下载的所有库,然后使用Google Eclipse插件“Google / Add Google APIs ...”下载所有最新版本。

相关问题