I typically use the Google Analyticator plugin to setup Google Analytics for client projects and haven’t had that many issues using it over the years and I probably have it on 100+ websites. Well, lately I’ve noticed a few client dashboards w/ the following error message:
Fatal error: Uncaught exception ‘Google_AuthException’ with message ‘Error refreshing the OAuth2 token, message: ‘{ “error” : “invalid_grant” }” in /home/xxxxx/public_html/cms/wp-content/plugins/google-analyticator/google-api-php-client/src/auth/Google_OAuth2.php:279 Stack trace: #0 /home/ffbsst/public_html/cms/wp-content/plugins/google-analyticator/google-api-php-client/src/auth/Google_OAuth2.php(239): Google_OAuth2->refreshTokenRequest(Array) #1 /home/xxxxx/public_html/cms/wp-content/plugins/google-analyticator/google-api-php-client/src/auth/Google_OAuth2.php(216): Google_OAuth2->refreshToken(‘1/zd433lhEC7Azn…’) #2 /home/xxxxx/public_html/cms/wp-content/plugins/google-analyticator/google-api-php-client/src/service/Google_ServiceResource.php(166): Google_OAuth2->sign(Object(Google_HttpRequest)) #3 /home/xxxxx/public_html/cms/wp-content/plugins/google-analyticator/google-api-php-client/src/contrib/Google_AnalyticsService.php(183): Google_ServiceResource->__call(‘list’, Array) #4 /home/xxxxx/public_html/cms/wp-co in /home/ffbsst/public_html/cms/wp-content/plugins/google-analyticator/google-api-php-client/src/auth/Google_OAuth2.php on line 279
I did a little research on this and found out that I’m not the only one seeing this issue, see WordPress Support Forum Here…
I finally did find a solution shared by Jeremy Clarke that seems to work. If you will checkout his gist here and replace the Google_OAuth2.php file w/ his code, then de-activate and reactivate & reset your Google Analyticator plugin you can get your site back up and running.
No word on what causes this bug to happen, it’s pretty sporadic among my clients…
Questions or Comments?