Implementing full sync with gmail api

I am using google php library which works with gmail api

. I want to get all messages from my gmail account.

How I do it:

        do {
            $this->client->setUseBatch(false);
            $messagesResponse = $service->users_messages->listUsersMessages('me', compact('pageToken'));

            if ($messagesResponse->getMessages()) {
                $batch = new Google_Http_Batch($this->client);
                $this->client->setUseBatch(true);

                foreach ($messagesResponse as $item) {
                    $request = $service->users_messages->get('me', $item->id, ['format' => 'raw']);
                    $batch->add($request);
                }

                $messages = array_merge($messages, $batch->execute());
                $pageToken = $messagesResponse->getNextPageToken();
            }
        } while ($pageToken);

      

When I run this script from the CLI I got the following error:

[Google_IO_Exception] Firing
      time after 100000 milliseconds with 57157107 bytes received

If I comment out the line fetching the new token then I get the first 100 messages and it works. But I can't get them. PHP has no timeout, it's google_io_exception, so I don't know how to solve the problem. Plus any optimization tips would be great as the only thing I know is batch queries, but I use them.

+3


source to share


1 answer


This question is still relevant, and since it took me a long time to get a clear answer, I will share what I found:

You are limited to 100 calls in one batch request. If you need to make more calls, use multiple batch requests.

https://developers.google.com/gmail/api/guides/



As you can see, based on the documentation, you cannot have more than 100 calls in one batch request. Therefore, you will have to calculate and execute below this limit.

If you support this limit of 100 requests, everything should work fine.

0


source







All Articles