I create a channel that receives changes for users who are in my application. The main problem is that after 2-3 websites I get an error message indicating that the user has exceeded the quota limits.
This does not make sense because I received only 2 messages (I saw this on ngrok).
I went to the Google console for the disk API and quota. Each time I receive a webhook, the number of requests increases by 500. Thus, when a user makes two changes, and I receive two web hosts, the number of requests exceeds 1000 allowed by Google, and I get this error.
This code where I turn on 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();
}
And the following website:
@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 mistake:
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 is this happening?