Google Analytics Core Reporting API Version 3.0 No Login

I want to access our Google Analytics account using the new version v3.0, but it seems that from everything that I read, in order to get a valid access token, the user must log in.

We want direct access to our own account, and not to the client, depending on their account. How to do this in PHP without having to send a browser to the Google login page? Is there a direct authentication API for v3.0?

EDIT

This is apparently the only method of accessing the API without interacting with the end user, which they call "Server to Server":

https://developers.google.com/accounts/docs/OAuth2ServiceAccount

EDIT 2

It seems like it's impossible to do ?; (

Warning: Very few Google APIs currently support service accounts. Currently, service accounts are supported by the following Google services developer services:

  • Google Cloud Storage
  • Google Prediction API
  • Google URL Extender
  • Google OAuth 2.0 Authorization Server

EDIT 3

It seems that there is a solution when I log in once, and then use Update Tokens to gain access without additional user input.

+7
source share
1 answer

As a result, I used update tokens, they work fine. I got the oauth token using the google api console and then saved it.

Then I just do this before each request:

require_once 'google-api-php-client/src/apiClient.php'; require_once 'google-api-php-client/src/contrib/apiAnalyticsService.php';; $client = new apiClient(); $client->setApplicationName('My Analytics'); $client->setClientId($this->client_id); $client->setClientSecret($this->client_secret); $client->setDeveloperKey($this->api_key); $client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly')); $client->refreshToken($this->refresh_token); $this->service = new apiAnalyticsService($client); 
+1
source

All Articles