Search code examples
google-my-business-apigoogle-my-business

RATE_LIMIT_EXCEEDED exception on getting Account List(Google My Business API)


Nowadays we are implementing My Business api integration for our platform. I followed this document "https://developers.google.com/my-business/content/prereqs" and after I trying to get account list an error occurred;

<HttpError 429 when requesting https://mybusinessaccountmanagement.googleapis.com/v1/accounts?alt=json returned "Quota exceeded for quota metric 'Requests' and limit 'Requests per minute' of service 'mybusinessaccountmanagement.googleapis.com' for consumer 'project_number:XXXX'.". Details: "[{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'RATE_LIMIT_EXCEEDED', 'domain': 'googleapis.com', 'metadata': {'quota_metric': 'mybusinessaccountmanagement.googleapis.com/default_requests', 'consumer': 'projects/XXXX', 'quota_limit': 'DefaultRequestsPerMinutePerProject', 'service': 'mybusinessaccountmanagement.googleapis.com'}}]">

 output = self.service.accounts().list().execute();

Anyone faced this type issue ?

Regards.


Solution

  • You can use a rateLimiter:

    import com.google.api.client.json.GenericJson;
    import com.google.common.util.concurrent.RateLimiter;
    

    ...

    //requests per second
    private static final RateLimiter rateLimiter = RateLimiter.create(5.0);
    

    ...

    private static GenericJson executeWithRateLimiter(request,
                RateLimiter rateLimiter) {
       rateLimiter.acquire();
       return request.execute();
    }