Why do I get 429 error telling me that user-rate limit exceeded when I use only one request?:
$messagesResponse = $service->users_messages->listUsersMessages('me');
I got this error recently, I've checked my quotas, and as I got it listUserMessages
(messages.list request) counts as 5 units, and I got 250 limit in a second.
Really can't figure it out.
Some code (here I also use search query, but it doesn't matter if I have the "q" param or not"):
class MessageReceiver implements ReceiverContract {
/**
* @var Google_Client
*/
protected $client;
/**
* Inject dependencies.
*/
public function __construct()
{
$this->client = new Google_Client();
$this->client->setClientId(config('services.gmail.clientId'));
$this->client->setClientSecret(config('services.gmail.clientSecret'));
}
public function searchMessages($user, $query)
{
$this->client->refreshToken($user->google_refresh_token);
$service = new Google_Service_Gmail($this->client);
$pageToken = null;
$messages = [];
do {
$this->client->setUseBatch(false);
try {
$messagesResponse = $service->users_messages->listUsersMessages('me',
['pageToken' => $pageToken, 'q' => $query]
);
} catch (\Google_Service_Exception $e) {
dd($e->getErrors()); // 429 error
}
...
}