Google Analytics Oauth2 refresh token

Hey everyone!

I have been stuck all day trying to figure out how to keep an Oauth2 connection to a Google Analytics 4 API alive for more than an hour. The Oauth2 connection works great, but has a default time to live of 1 hour. So I have to manually refresh the authentication every hour. I can’t find any documentation or examples of getting a refresh token to work with Google (that don’t seem overly complicated anyway). Does anyone have a simple way to keep a Google Oauth2 authentication valid for more than an hour?

Here are my current settings that work one hour at a time.

Welcome to the Make community!

You might need to set your OAuth application to “Production”, otherwise the credentials expire very frequently.

1. To do this, go to menu item “OAuth consent screen”

or click here https://console.cloud.google.com/apis/credentials/consent

2. Then click the button below if the Publishing status is not “In production”

3 Likes

@samliew Thank you so much for the detailed response! I did check that setting and I am fully published. I’m still not sure what to do as I can’t develop a webhook that I have to reestablish an authentication with Google every hour. Everything in my research is pointing me to a refresh token, but I can’t figure out how I would support that in Make.

You are probably talking about redirect URI.

The current redirect URI is https://www.integromat.com/oauth/cb/app.

More info can be found in OAuth 2.0 docs.

2 Likes

@Tereza Thank you for your response and sorry for my delay. Just getting back to this challenge. Can you help me understand this a bit more. Currently I am using…

https://www.integromat.com/oauth/cb/oauth2
https://www.integromat.com/oauth/cb/google/

for my “Authorized Redirect URLs”. Should I be adding in the one you have provided as a 3rd URL, or is one of the above incorrect?

Thanks ahead of time.

Welcome to the Make community!

Here are all the known redirect URIs you need for your Google Cloud Console OAuth app

https://www.make.com/oauth/cb/google-custom
https://www.make.com/oauth/cb/google-restricted
https://www.make.com/oauth/cb/google-cloud-speech
https://www.integromat.com/oauth/cb/google-custom
https://www.integromat.com/oauth/cb/google-restricted
https://www.integromat.com/oauth/cb/google-cloud-speech

Once you’ve set these up, you can use/reuse the same Make connection for all the supported Google apps & modules on Make - you’ll only have to enable the respective APIs for your custom app in Google Cloud.

Hope this helps!

2 Likes

Hi @samliew

Thank you for this information. When I add all of these to my app as listed below, the Oauth2 connection now throws an error that says Redirect URI Mismatch. It doesn’t seem like this is the right configuration. Everything was working with my original config (as imaged below), but the app would timeout every 60 minutes or so and force me to manually refresh the connection. Any thoughts on how to work around this? Or is there anyone in the community that I could hire to help here?

image

Working config that times out after an hour.
image

Do you use a custom app? If so, remove the expiration of refresh token from the connection’s code. Google doesn’t expire the refresh token and it is a common mistake of developers:

2 Likes

@Tereza Thank you for your continued interest in helping! I am obviously not an expert on this stuff. I have a Google Project setup that enables the Google Analytics API. I’m trying to just get a standard HTTP Oath 2.0 connection to not require a manual refresh all the time.

Unfortunately, the GA4 standard application within Make forces a property ID into the authorization connection which won’t work for me. So I need to create an HTTP call, but continue to run into timeout issues.

Any other thoughts, or reference where I can find this allusive “expires” setting.

Thanks!

Since your issue is not related to a custom app, I am moving your question to Questions & Answers group.

2 Likes

@samliew

Here is what I was able to figure out with help from support. This configuration allows me to authenticate a single time without me having to manually store a refresh token. It also allows me to query any property that I have permissions for by changing the property in the Base URL field. It’s not ideal because I have to manually write the full API query in the Body field. The whole reason I employ Make is so I don’t have to write API queries…but…it does work. Hope this helps someone else.

  1. I can only use the GA4 “Make API Call” function. The other functions wouldn’t work for me.

  2. The Redirect URI on my Google app needed to be https://www.integromat.com/oauth/cb/google-analytics-4

  3. Configure the “Make API Call” fields as follows…entering your own property ID where the blacked out text is.

4 Likes

Aha, this is new information. Thanks for letting me know, and I’m glad you got it solved!

3 Likes