Integrating Google Analytics Using REST & OAuth 2.0 token expiry


(Tim Trodd) #1

Hello,

I have followed this manual:

Which works great except for when the initial access token expires? It lasts for one hour and then after that time, it stops working and when I run a test it says no refresh token available? I have all the settings exactly the same as in the manual e.g. global permanent token etc. but I am having to manually refresh the token each time after it has run out to make things work again.

Any ideas? I have the locks when it initially sets the initial token and like I said it all works fine up until the expiry time passed.

Cheers,

Tim

system - 5.3.1.1


(Bart Banda) #2

Hmm, that’s weird. I just tried to force get a new token and this time it didn’t save the refresh token for me.

To fix it, I had to go to the Apps connnectd to your accounts page in Google:
https://myaccount.google.com/u/1/permissions?pli=1&pageId=none

Delete the access to my Squiz Matrix site, and then re-authenticate the token.

You can do that by viewing the URL of the Token in a browser, like you did when you first would have gone to make a request for authentication to Google, but add ?force=true a the end of it.

Eg. https://matrix.squiz.net/configs/google-analytics-token?force=true

Can you try doing that to see if it works?


(Tim Trodd) #3

Thanks Bart that worked great! Refresh token appears now and works as it should.

Cheers,
Tim


(Luke Wright) #4

Hi TT,

I just got pointed to this recently. Just as an additional element:

The tutorial’s authentication should have an extra query string:
https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&prompt=consent

The tutorial doesn’t mention the extra query string parameter, but the extra query string is important if you have to **RE-**authenticate (eg. revoke and re-authorise) - normally Google would not provide an additional consent screen for this, but Google also won’t provide a refresh token unless you see a consent screen.

This consent screen should simply ask you for “offline access” because you already have the correct scopes authorised on that account.

I’m looking to get the tutorial updated with this; the rest of it looks fine to me though.

Hope this helps :slight_smile:

~ Luke


(Tim Trodd) #5

Thanks for the tip! It is all working now!


(Bart Banda) #6

I’ve also updated the tutorial to reflect this.