-
Methods for sending access token to Google Analytics 4 Admin API
So, I’ve been playing around with the PHP library for the Google Analytics 4 admin API. The issue that I’ve stumbled upon is that I can’t seem to get the accounts list, and I think it’s because I’m not correctly passing the auth access_token. I’m not really sure about how to do that though. To make it clearer, here’s the piece of code I’ve been using:
require 'vendor/autoload.php'; use GoogleAnalyticsAdminV1alphaAnalyticsAdminServiceClient; use GoogleAnalyticsDataV1betaBetaAnalyticsDataClient; use GoogleAnalyticsDataV1betaDateRange; use GoogleAnalyticsDataV1betaDimension; use GoogleAnalyticsDataV1betaMetric; putenv('GOOGLE_APPLICATION_CREDENTIALS=config.json'); $access_token = "**********"; $client = new AnalyticsAdminServiceClient(['access_token' => $access_token]); // is this the correct way to pass the token? $accounts = $client->listAccountSummaries();
I’m kind of stuck on figuring out the right way to use the access token with this API. Anyone who could guide me through this?
Also, just for additional context this is what my JSON file looks like:
{ "type": "service_account", "project_id": "**********************", "private_key_id": "**********************", "private_key": "**********************", "client_email": "**********************.iam.gserviceaccount.com", "client_id": "**********************", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_x509_cert_url": "*******************" }
Log in to reply.