问题
This is the question for GAPI users which shut down yesterday:
https://code.google.com/p/gapi-google-analytics-php-interface
GAPI - Google Analytics API PHP Interface was a simple yet powerfull Google Analytics library. It was using the old API and required full Google username and password which was really old fashioned but it was working like a charm. bUT here we are, our GAPI based codes gives the message:
Failed to authenticate user AuthForInstalledApps
The only option is to use the oAuth2.0, so what we got here?
Google Client Libray: https://github.com/google/google-api-php-client
The issue with this library is, it's a common library, not just for Analytics. So if you're going to use it just for Analytics, it has lots of unnecessary classes like, Fitness, Adsense, Book, Blogger? The good side was, we can use just one basic php class to do the whole work, now why do we need to use thousand lines of codes?
I really read lots of Q&A, tried nearly all the PHP classes for that issue but they all referenced Google Client Library. When I found wanze's Analytics API I was really excited because it's using Oauth 2.0 and an updated library but this line returned empty, so it didn't work.
$auth = $ga->auth->getAccessToken($code);
So here we are, looking for a lightweight PHP library just for Google Analytics, using oAuth2, what's your suggestions beside Client Library?
回答1:
I am maintainer and was contacted today regarding GAPI and the OAuth2 requirement. Just released Version 2.0 on GitHub from contributions from the community.
Version 2.0 is a straight port from 1.3/1.4 and should match your existing system. Note that OAuth2 will require you to create a 'service account' and then download a P12 file to upload to the server. Finally you will need to adjust the developers console, enable 'analytics API'. Finally give this new user 'Read and Analyse' permissions on the Google Analytics accounts you want to access.
回答2:
Hello Have you tried working through the recently updated Hello Analytics API for PHP? It goes through two different authentication methods. The web app and service account.
You will probably need to update the underlying client library.
回答3:
Had the same situation and just made the switch to Google Client Libray: https://github.com/google/google-api-php-client. Trust me, its not bad at all. I prefer lightweight but its pretty easy to use and you don't see much of the excess weight. The reason I would recommend it, once you make the switch, you can leverage Google tools (Analytic Query editor for example) and documentation. Took me an hour or so to 'port' my code. Rather than using a service account and certificate, I just save and store my oauth access token.
This article can help you with setup: http://www.daimto.com/google-oauth2-php/ and the code for actually doing the analytics i have examples of here (in my answer): Get function in Google Analytics API
来源:https://stackoverflow.com/questions/30477341/gapi-is-shutting-down-need-a-lightweight-php-api-for-google-analytics