Google Drive 服务帐号返回 403 usageLimits

Google Drive service account returns 403 usageLimits(Google Drive 服务帐号返回 403 usageLimits)
本文介绍了Google Drive 服务帐号返回 403 usageLimits的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试编写一个 AppEngine 应用程序,该应用程序将 Google 文档写入 Google Drive,放入一组特定的文件夹并设置访问权限.我可以使用旧的 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).

我面临的问题是:当我使用服务帐户并尝试模拟特定用户时,即使我没有用完任何配额,我也会收到带有 usageLimits 的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Reliable implementation of PBKDF2-HMAC-SHA256 for JAVA(PBKDF2-HMAC-SHA256 for JAVA 的可靠实现)
Correct way to sign and verify signature using bouncycastle(使用 bouncycastle 签名和验证签名的正确方法)
Creating RSA Public Key From String(从字符串创建 RSA 公钥)
Why java.security.NoSuchProviderException No such provider: BC?(为什么 java.security.NoSuchProviderException 没有这样的提供者:BC?)
Generating X509 Certificate using Bouncy Castle Java(使用 Bouncy Castle Java 生成 X509 证书)
How can I get a PublicKey object from EC public key bytes?(如何从 EC 公钥字节中获取 PublicKey 对象?)