1. Setup

First, we need to activate access to Google Analytics API by going to https://code.google.com/apis/console/ > All services > Analytics API:


Then, we need to add 'https://www.googleapis.com/auth/analytics.readonly" to the requested scope on hybridauth configuration file:

  1. "Google" => array (
  2. "enabled" => true,
  3. "keys" => array ( "id" => "", "secret" => "" ),
  4. "scope" => "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/analytics.readonly"
  5. ),

2. Use Hybrid_Providers_Google::api() to make appropriate Google API calls:
  1. <?php
  2. $hybridauth = new Hybrid_Auth( $config );
  3.  
  4. $google = $hybridauth->authenticate( "Google" );
  5.  
  6. $data = $google->api()->api( "https://www.googleapis.com/analytics/v3/management/accounts" );
  7.  
  8. print_r( $data );

* For more information about Google Analytics API you can refer to https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/.