Google Analytics API V3 / OAuth 2

时光总嘲笑我的痴心妄想 提交于 2019-11-30 13:42:21

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);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!