Fetch Access Token and Refresh Token from Gmail API Oauth2 Call to request new access token

I run into the typical problems integrating Gmail API, a day after I have set up an authorized my OAuth2 Client (using all steps described in various posts on how to set up a Google Workspace Oauth consent screen and client). The API call succeeds first time, but a day later I run into the 401 error telling me the token is not valid anymore. Authorizing the connection on a daily basis manually is not a feasible solution.

I would consider fetching the refresh token, storing this into a data store and before running the scenario with the HTTP/Oauth call to Gmail send along the new access token.

Is that feasible, and if yes, how would I get the refresh token from the initial request???

It seems most of the other Google Modules on make have this solved internally, BUT the Gmail Make Module has no “Make API calls” feature. Using HTTP OAUTH Request has also does not store the Access Token and Handle its refresh after it expires (currently 1hr), so one is left with the error message that the token is not valid after the first calls worked.

With some searching in the community I found the post of @sean, mentioning the video of Aron that describes how to handle Google’s APIs with Oauth2 (including the piece I missed, the refresh token and how to store it in make data store to request new tokens on demand or scheduled) https://www.youtube.com/watch?v=bv0SPPBYGHI&t=2815s&pp=ygUUYWF0dCBrb3JlbmJsaXQgb2F1dGg%3D

Works like a charm, once you watched the WHOLE VIDEO (!!!) and understood the flow of things!

Thanks again @sean for pointing us there!!!

3 Likes

Happy this helped! Aron’s video has 1,725 views –– who knows how many of those are mine! :joy: