简体   繁体   中英

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. And there I see 10,000 queries per day (Courtesy Limit). Actually my program makes 170-190 requests per hour after that receives such response from Google+ API:

{
"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. But 190 requests per hour * 24 hours is far from 10,000.

I am using method people.search and google-api-java-client library version 1.15.0-rc. Initialize Plus service like below:

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. 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).
  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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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