我知道那里有配额:https ://code.google.com/apis/console 但这些是每日配额。我看到每天有 10,000 个查询(礼貌限制)。实际上,在收到来自 Google+ API 的此类响应后,我的程序每小时发出 170-190 个请求:
{
"code" : 403,
"errors" : [ {
"domain" : "usageLimits",
"message" : "Rate Limit Exceeded",
"reason" : "rateLimitExceeded"
} ],
"message" : "Rate Limit Exceeded"
}
1 小时后程序再次执行 170-190 直到得到相同的错误。但是每小时 190 个请求 * 24 小时远不是 10,000 个。
我正在使用方法 people.search 和 google-api-java-client 库版本 1.15.0-rc。初始化 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();
并使用这样的搜索方法:
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();
}
我试图将睡眠时间更改为 1 秒或 2 秒 - 相同的行为。试图重新生成密钥文件 - 没有运气。
我做错了什么吗?