I\'ve desperately tried to figure this out on my own, and did not want to come to SO with this question, but I\'m at my wits end (no thanks to the api / oauth docs).
Here’s my dim witted mistake that nearly gave me a heart attack.
I typically do my development work in Chrome. And my Chrome browser was signed into my gmail account personal@gmail.com
. However, my analytics account, which is under my work@gmail.com
was open in FireFox (try not to laugh to hard).
I’m not 100% sure this is correct, but I think this is the general flow. When I did STEP #2: Request initial API access
, I did this in my Chrome browser. The endpoint https://accounts.google.com/o/oauth2/auth
was authorizing my personal@gmail.com account. And my STEP #4 API request https://www.googleapis.com/analytics/v3/data/ga
was looking for an analytics profile under my personal@gmail.com account. Which of course doesn’t exist.
I literally wasted 15 hours on this. This is dumber than trying to troubleshoot an update… and forgetting to flush the cache.
Sorry for wasting your time.
EDIT REFRESH TOKENS
I've once again run into issues with this API and found out the hard way that GA will revoke Refresh Tokens if too many different clients use the token, at least I think that was the problem.
Further reading can be found here.
I got a 403 today and found the cause: in the get
function I was using the account ID instead of the profile ID. Switching to the profile ID fixed it for me.
It could be a problem with CURL request. In the GoogleAnalyticsAPI.class.php > class Http > function curl (around line 720)
add one more option to stop CURL from verifying the peer's certificate:
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);