Google Analytics "Invalid_Grant" Statistics Error Cause and Fix

Jul 2, 2014 3:21 pm

If you are receiving the following "Invalid_Grant" error in your Statistics module and the Account Bridge is "breaking" here is what is going on:

The reason there is an "Invalid_Grant" error is because the account's grant token has expired.

This usually happens because a user has a very large number of properties on the account, and because there are a finite number of active authorization tokens, eventually the oldest ones authorized will get unauthorized by Google.

To avoid future "breaks" in the bridge please refrain from putting more clients on the existing Google Analytics account than Google allows. If you need to add more than what Google allows we recommend opening another Google Analytics Admin User, add (authorize) it to the account, and limit each one to the allowances outlined by Google below.

Google says:

"If you need to authorize multiple programs, machines, or devices, one workaround is to limit the number of clients that you authorize per user account to 15 or 20. If you are a Google Apps admin, you can create additional admin users and use them to authorize some of the clients.

"There is currently a 25-token limit per Google user account. If a user account has 25 valid tokens, the next authentication request succeeds, but quietly invalidates the oldest outstanding token without any user-visible warning."

Source: https://developers.google.com/accounts/docs/OAuth2 "Token expiration" section.

Jul 2, 2014 4:10 pm

You also may see the error message:

There was a general error : Error refreshing the OAuth2 token, message: '{
"error" : "invalid_grant" }'