Google Drive API配额已超出 [英] Google Drive API quota exceeded

查看:865
本文介绍了Google Drive API配额已超出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个可以接收我的应用程序中的用户更改的频道。主要问题是,在2-3个webhooks之后,我收到一个错误,指出用户已超出配额限制。

I'm creating a channel that receive changes on users that are on my application. The main problem is that after 2-3 webhooks, I receive an error that says that user has exceeded the quota limits.

这没有意义,因为我只收到2个发布消息(我在ngrok上看到过)。

That has no sense, because I only received 2 post message (I saw it on ngrok).

我在驱动程序API和配额上使用了Google控制台。每次我收到一个webhook时,查询的数量增加了500个。所以,当一个用户做出两个更改并且我收到两个webhook时,查询的数量超过了google允许的1000,并且我收到了这个错误。

I've went on google console on drive API and quota. Each time I receive a webhook the amount of queries is increased by 500. So, when a user make two changes and I receive two webhooks, the number of queries exceed the 1000 allowed by google and I receive that error.

这是启用频道的代码:

That's the code where I enable the channel:

    @GET
    @Path("/enable")
    public void enable(@Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException {
        Credential credential = initFlow().loadCredential("user");
        Drive service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
        Channel channel = new Channel(); 
        channel.setId(UUID.randomUUID().toString());
        channel.setType("web_hook");
        channel.setAddress("https://389825dc.ngrok.io/GDriveRest/app/gdrive/webhook");
        StartPageToken page = service.changes().getStartPageToken().execute();
        GDrive.savedPageToken = page.getStartPageToken();
        service.changes().watch(savedPageToken, channel).execute();
    }

以下是webhook:

And the following one is the webhook:

    @POST
    @Path("/webhook")
    public void webhook(@Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException {
        Credential credential = initFlow().loadCredential("user");
        Drive service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
        String pageToken = savedPageToken;

        while (pageToken != null) {
            ChangeList changes = service.changes().list(pageToken).execute();

            for (Change change : changes.getChanges()) {
                Log.info("Change found for file: " + change.getFileId());
            }
            if (changes.getNewStartPageToken() != null) {
                savedPageToken = changes.getNewStartPageToken();
            }
            pageToken = changes.getNewStartPageToken();
        }
        response.setStatus(200);
    }

这是错误:

This is the error:

Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
  "code" : 403,
  "errors" : [ {
    "domain" : "usageLimits",
    "message" : "User Rate Limit Exceeded",
    "reason" : "userRateLimitExceeded"
  } ],
  "message" : "User Rate Limit Exceeded"
}

为什么会发生这种情况?

Why this is happening?

推荐答案

代码中存在错误。我不得不改变以下内容:

There was an error in the code. I had to change the following:

PageToken = changes.getNewStartPageToken();

pageToken = changes.getNextPageToken();

大量的查询是因为我在每个循环中请求一个新的起始页标记,迫使无限循环。

The huge amount of queries was because I was requesting on every loop a new start page token, forcing an infinite loop.

这篇关于Google Drive API配额已超出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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