Analytics PHP Interface (GAPI) Custom Impersonation

Currently, I have about 100 sites in Google Analytics in several different Google accounts, and one account has full permissions for each site. If possible, I would not want to manually add permissions for the Google Service account to each analytics profile.

I am using the Google Analytics PHP interface

When I try to impersonate a user using the $ delegate_email argument, I get the following exception:

GAPI: Failed to authenticate user. Error: "{ "error": "unauthorized_client", "error_description": "Unauthorized client or scope in request." } 

I read elsewhere about the need to "Delegate domain authority for a service account" using the Google Apps admin console. However, we do not have Google Apps. Is there any way around this?

TL; DR Is there a way to read-only access to Google Analytics using a service account and impersonating a user without Google Apps?

+5
source share
1 answer

First, I would advise you to look at the various Scripts listed in the Google OAuth 2.0 documentation and decide which one is best for your application.

A service account requires that you add a user to each account that you want to access, but from a web server , the end user simply allows your application to read their Google Analytics data.

Search Area:

 https://www.googleapis.com/auth/analytics.readonly 
+2
source

All Articles