I am trying to present some basic data from our Google Analytics accounts directly on our company's backend. I am using the Google API PHP Client.
I have followed the Hello Analytics API tutorial but it leaves me with the obligation to connect from a browser. I need the info to be available from the server itself (without browser client connection) as I would like to automate the queries from within a Cron task.
Is what I want to do possible? Am I using the correct PHP API? Is there a different way to get back GA data?
Why won't you replace your google analytics service with something like Piwik!
I skimmed through the links you provided and near as I can tell, it doesn't obligate you to connect from a browser. First off, are you sure you looked at the "php" tab in that tutorial? The walkthrough uses browser interaction, but you can easily make it do something else instead of output to the browser.. I'm guessing maybe 2.6 might be where you got confused...but that's just an example of prompting the user to login, under the assumption that you are making a web interface. For your purposes, you would be authenticating with 2.4, and as far as 2.6 is concerned, you could have your script do something else if that condition is true (like log a "failed to connect" error). And instead of printResults
echoing out stuff (because the tutorial assumes browser interface) you could do something else with it, like write to a db or something. IOW I don't see anything in that tutorial that requires browser interaction, other than they just did that as an example for the sake of the tutorial.
The answer has been given elsewhere by an actual genius, @rkarbowski.
Service Applications and Google Analytics API V3: Server-to-server OAuth2 authentication?
I believe if you follow the Hello Analytics API Tutorial and then read @rkarbowski's answer, and especially the update, carefully, you will be able to make it work. I have, and I am no genius.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With