Google Drive 服务帐户返回 403 usageLimits [英] Google Drive service account returns 403 usageLimits

查看:34
本文介绍了Google Drive 服务帐户返回 403 usageLimits的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个 AppEngine 应用程序,该应用程序将 Google 文档写入 Google 云端硬盘,放入一组特定的文件夹并设置访问权限.我使用旧的 DocsList API 进行了这项工作,但由于它刚刚被弃用,我决定更新我的代码(无论如何我还有一些额外的功能要添加).

I'm trying to write an AppEngine app that writes a Google Document to Google Drive, puts in a specific set of folders and sets access rights. I have this working with the old DocsList API but since that just got deprecated I decided to update my code (and I had some additional functions to add anyway).

我面临的问题是:当我使用服务帐户并尝试模拟特定用户时,即使我没有用完我的任何配额,我也会收到带有使用限制的 403.

Problem I'm facing is this: When I use a service account and try to impersonate a specific user I get a 403 with usageLimits even though I have not used up any of my quota.

这是我正在使用的代码:

Here is the code I'm using:

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 对象:

I than use these credentials to initiate my Drive object:

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();

顺便说一句:我试过使用 new Drive(....) 但是不管我怎么尝试都行不通.不断抛出找不到内部方法的错误!

BTW: I've tried using new Drive(....) but that just won't work, no matter what I try. Keeps throwing errors that internal methods are not found!

回到这个问题:当我使用 'd' 调用类似 .files().get("SOMEFILEID").execute() 之类的东西时,我得到一个 403

Back to this issue: When I than use 'd' to call something like .files().get("SOMEFILEID").execute() I get a 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"
}

我不明白为什么这不起作用.我在网上看了一整天,但找不到合适的答案.非常感谢您的帮助.

I can't figure out why this doesn't work. I've look online all day but can't find a suitable answer. Some help is very much appreciated.

推荐答案

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

I usually get a 403 when the API call was missing the Authorization http header. Trace the http and look at the headers. The rationale for the "quota" message is that without an Auth header, you are anonymous, and the quota for anonymous use is zero.

您还可以检查您的应用是否注册了两个 Drive API,因为我听说这可能会导致相同的问题.

You might also check that your app is registered for both of the Drive APIs, as I've heard that that can cause the same problem.

关于内部方法问题,听起来您使用的是不兼容的库版本.对我来说最有效的是删除我用示例代码下载的所有库,然后使用 Google Eclipse 插件Google/Add Google APIs..."下载所有最新版本.

On the internal method issue, that sounds like you're using incompatible library versions. What worked best for me was to delete all of the libraries I had downloaded with the sample code, then use the Google Eclipse plugin to "Google/Add Google APIs..." to download all of the latest versions.

这篇关于Google Drive 服务帐户返回 403 usageLimits的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆