简体   繁体   English

Google+ API是否有任何每小时费率限制?

[英]Does Google+ API have any hourly rate limit?

I know there are quotas there: https://code.google.com/apis/console But these are daily quotas. 我知道那里有配额: https//code.google.com/apis/console但这些是每日配额。 And there I see 10,000 queries per day (Courtesy Limit). 在那里,我每天看到10,000个查询(Courtesy Limit)。 Actually my program makes 170-190 requests per hour after that receives such response from Google+ API: 实际上,我的程序在收到Google+ API的响应后,每小时会收到170-190个请求:

{
"code" : 403,
"errors" : [ {
"domain" : "usageLimits",
"message" : "Rate Limit Exceeded",
"reason" : "rateLimitExceeded"
} ],
"message" : "Rate Limit Exceeded"
}

After 1 hour program does 170-190 again till get same error. 1小时后程序再次执行170-190直到得到相同的错误。 But 190 requests per hour * 24 hours is far from 10,000. 但每小时190个请求* 24小时远远不是10,000个。

I am using method people.search and google-api-java-client library version 1.15.0-rc. 我正在使用方法people.search和google-api-java-client库版本1.15.0-rc。 Initialize Plus service like below: Initialize Plus服务如下:

HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        JsonFactory jsonFactory = new JacksonFactory();
        GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
                .setJsonFactory(jsonFactory)
                .setServiceAccountId(EMAIL)
                .setServiceAccountScopes(Collections.singleton(PlusScopes.PLUS_LOGIN))
                .setServiceAccountPrivateKeyFromP12File(KEY_FILE))
                .build();
        Plus plus = new Plus.Builder(httpTransport, jsonFactory, credential)
                .setApplicationName(APP_NAME).build();

And use search method like this: 并使用这样的搜索方法:

Plus.People.Search searchPeople = people.search(fullname);
    searchPeople.setMaxResults(50L);
    searchPeople.setFields("items(id),nextPageToken");
    PeopleFeed peopleFeed = searchPeople.execute();
while (true) {
        if (peopleFeed.getItems().size() == 0) {
            break;
        }

        /* Save people info here */

        if (peopleFeed.getNextPageToken() == null) {
            break;
        }
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) { }
        searchPeople.setPageToken(peopleFeed.getNextPageToken());
        peopleFeed = searchPeople.execute();
    }

I tried to change sleep time to 1 sec or 2 sec - same behaviour. 我试图将睡眠时间改为1秒或2秒 - 同样的行为。 Tried to regenerate key file - no luck. 试图重新生成密钥文件 - 没有运气。

Did I do something incorrect? 我做错了吗?

The issue is threefold: 问题有三个:

  1. The rate limit is both per day (10,000) and per second (5). 速率限制是每天 (10,000)和每秒 (5)。
  2. The error message is shared between the types. 错误消息在类型之间共享。
  3. The time until the next window is not provided. 没有提供下一个窗口的时间。

Thus, I have my applications wait rand(1,5) seconds and if they are rate limited again, I wait 3600 seconds before retrying. 因此,我的应用程序等待rand(1,5)秒,如果它们再次受到速率限制,我会等待3600秒再重试。

If you go to the Quotas link at the API Console you indicated, it will break down the daily limit for your app's usage of each API, but will also list a per-user quota. 如果您转到您指定的API控制台的Quotas链接,它将分解您的应用使用每个API的每日限额,但也会列出每用户配额。 For example, mine currently shows 例如,我的目前显示

Google+ API    5.0 requests/second/user

In general, their API endpoint may allow bursts more than this, and this should be considered an estimate, but going over this limit for extended durations may cause the rate limit exceeded error you see. 通常,它们的API端点可能允许突发更多,这应该被视为估计值,但是在延长的持续时间内超过此限制可能会导致超出速率限制的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM