Reputation: 63
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?
Upvotes: 6
Views: 4155
Reputation: 31511
The issue is threefold:
Thus, I have my applications wait rand(1,5)
seconds and if they are rate limited again, I wait 3600
seconds before retrying.
Upvotes: 8
Reputation: 50721
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.
Upvotes: 1