Search code examples
phpgoogle-analyticsgoogle-analytics-api

Using Service Account For Google Analytics


I wanted to create a web service like feature that would provide me the JSON response from the google analytics, i plan to do some processing on the GA data and then output the response to the user who would have requested for my service.

I selected PHP as my language and used google-api-php-client from google and now since i don't want to authorize every time to get Token, i thought of using Service account with which i would directly use keys.

I downloaded the sample code from Google changed client ID and Service Account Name and Key location.

But then this Error Came

Catchable fatal error: Argument 3 passed to Google_HostedmodelsServiceResource::predict() 
must be an instance of Google_Input, none given, called in /var/www/webservice/GA/serviceanalytics.php 
on line 62 and defined in /var/www/webservice/GA/google-api-php-client/src/contrib/Google_PredictionService.php on line 36

I found that the second argument that example is passing should have been the third argument.

So what should be the second argument. A little insight or a working code will be appreciated :)

Thanks


Solution

  • The link you have posted svn/trunk/examples/prediction/serviceAccount.php

    Is for use with Google Preditions api If you have supplied a client ID and Service Account Name and Key location for an api that was set up to allow google analytics this wont work. I sugest you look for an example using Google Analtyics or change the apis console to allow preditions api while you are getting to know the sample code for Google Preditions.