Sgarz
Sgarz

Reputation: 331

Google PHP API Analytics gives strange userRateLimitExceeded

Since GAPI stopped working two days ago I had to rewrite some code for my Google Analytics dashboard. I decided to use the Google API PHP Client (https://github.com/google/google-api-php-client) I got it all working pretty nice at my local Vagrant Ubuntu server but when I deploy the code to my remote webserver I get a 500 PHP error. When checking the logs I discover that the error message it creates is

(403) Quota Error: User Rate Limit Exceeded.

How can this code be working on my Vagrant but not on my remote webserver? The domains are both added correctly to the developers console. I tried setting the query/user/second-setting to 10 or more but that does not change anything.

Upvotes: 1

Views: 159

Answers (2)

Sgarz
Sgarz

Reputation: 331

Allright, so I fixed it:

I added a sleep(1); into the PHP foreach loop that was querying the Google Analytics profiles I have in my account. Apparently my VPS is querying Google's API faster than my local development environment does and therefore I was not getting any errors local.

Upvotes: 1

Metablocks Corp
Metablocks Corp

Reputation: 1665

Did the same thing (switched from GAPI to Google API PHP Client) but without any problems. According to the Google Analytics documentation, a 403 userRateLimitExceeded error means:

The user rate limit has been exceeded. The maximum rate limit is 10 qps per IP address. The default value set in Google Developers Console is 1 qps per IP address. You can increase this limit in the Google Developers Console to a maximum of 10 qps.

Something is obviously wrong since I am sure you are not exceeding those limits - but it may be related the IP address you are using (localhost for example). Not an expert but a couple of things you may want to check:

In the Google Developer Console for your application, visit:

  • APIs & Auth -> Analytics API -> Usage: Make sure this looks normal (something you are doing may be calling the API repeatedly make sure this isn't the case)
  • APIs & Auth -> Analytics API -> Quotas: Will tell you if Google thinks you are exceeding your quotas. Increase the Per user Limit (last item) and see if that does the trick
  • APIs & Auth -> APIs: Obviously make sure the Analytics API is enabled (can't imagine it isn't but check)

Upvotes: 0

Related Questions