Deconf.com

OAuth2 token errors with message: “error” : “invalid_grant”

This documentation page refers to Google Analytics Dashboard for WP (GADWP) plugin.

For other FAQ, tutorials, and helpful resources see the GADWP documentation index.

The last Google Analytics API error generated by the plugin is displayed under Google Analytics -> Errors & Debug screen. If something goes wrong, you should check this screen for the last error code and description.

In addition to the solution presented below, a full list of common error codes is available here.

Error refreshing the OAuth2 token, message: {“error” : “invalid_grant”}

Here are the possible reasons for the above error:

You can fix this by updating the date/time of your server or by asking your hosting provider to check it and make sure it is on sync. Using NTP sync is recommended.

There are multiple reasons for this case. Among them:

– You’ve revoked the authentication.

– The token wasn’t used for a long time and the authentication has expired.

– You’ve authorized the plugin with more than 25 sites using the same Google Analytics account.

Google has a limit of 25 active refresh tokens for a Client/Account pair. Here are some solutions if you need to authorize more than 25 sites:

– If your sites are all on the same WordPress Network (multisite mode), switch on this option: use a single Google Analytics account for the entire network. You’ll be able to use a single refresh token for all your network sites.

– Let your clients have their own Google Accounts. They will authorize the plugin using their own account. If you also need access to their analytics data (maintenance, or other contractual stuff) they can share the Properties/Views using the User Management feature from Google Analytics. (recommended)

– Create multiple API Projects, and authorize 25 sites or less per project. Unfortunately the plugin’s realtime reports won’t work without access to Realtime Reporting API.

– Use multiple Google Accounts of your own to authorize 25 sites or less per account. (not recommended)

Error fetching OAuth2 access token, message: ‘invalid_grant”

The error is generated when the user doesn’t have a properly configured Google Analytics account. Before authorization please make sure you’ve created at least one account, a property and a view on analytics.google.com.