Google云端硬盘服务帐户返回403个usageLimits [英] Google Drive service account returns 403 usageLimits

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

问题描述

我试图编写一个将Google文档写入Google云端硬盘的AppEngine应用程序,放入一组特定的文件夹并设置访问权限。我有这个工作与旧的DocsList API,但由于那只是不赞成我决定更新我的代码(我有一些额外的功能来添加)。

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



以下是我使用的代码:

  GoogleCredential凭证=新的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(凭证)
.setJsonHttpRequestInitializer(new JsonHttpRequestInitializer(){
@Override
public void initialize(JsonHttpRequest request){
DriveRequest driveRequest =(DriveRequest)request;
driveRequest.setPrettyPrint(true);
}
})。setApplicationName ( MYAPPNAME)建立();

顺便说一句:我试过使用新的驱动器(....),但不会工作,不管我尝试什么。不会发现内部方法没有找到的错误!



返回此问题:
当我比使用'd'调用类似.files()时。 get(SOMEFILEID)。execute()我得到一个403

  {code:403,
错误:[{
domain:usageLimits,
message:Daily Limit Exceeded。Please sign up,
reason:dailyLimitExceededUnreg,
extendedHelp:https://code.google.com/apis/console
}],
消息:每日限制已超出,请注册
}

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

解决方案

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



您也可以检查您的应用已经注册了两个Drive API,因为我听说可能会导致同样的问题。



在内部方法问题上,这听起来像您正在使用不兼容的库版本。最适合我的是删除我用示例代码下载的所有库,然后使用Google Eclipse插件Google / Add Google 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).

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

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

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!

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.

解决方案

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.

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.

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云端硬盘服务帐户返回403个usageLimits的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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