Search code examples
phpapigoogle-analyticsanalyticsauthsub

Authsub authentication with the GAPI code for Google Analytics API


I'm building an application that needs to authenticate users using Authsub. I have the authsub token already stored as $sessiontoken

I want to use this with the Google Analytics PHP interface (GAPI) but it only provides support for hard coded username and password:

`define('ga_email','removed@gmail.com');

define('ga_password','removed');

define('ga_profile_id','removed');

require 'gapi.class.php';

$ga = new gapi(ga_email,ga_password);`

How can I use my authsub token here instead?


Solution

  • The token can be passed as an optional parameter on the end of the constructor. Just use null for the username and password then your auth token:

    $ga = new gapi(null, null, $authToken);