1. Ensure you have the proper API (Google Calendar) enabled for the project you are working on.
Make sure this says “Manage” rather than “Enable.”
2. Install the Google OAuth Extension
Check out this video for a deep dive:
Optionally, include an Authorized redirect URI of http://localhost
if you don’t actually need to use this as part of user authentication flow but are rather using it only for API purposes.
Importantly, make your Client ID and Client secret environment variables in Xano.
3. Ensure you have the proper scopes enabled in the Google Cloud Console.
This a little tricky, but you should use the minimum necessary to accomplish your task in order to avoid providing excessive privileges to the application.
4. Generate an authentication link
Using the google_oauth_getauthurl function from the Google OAuth extension to generate an authentication URL and go through the process to authenticate to your Google account.
If that is successful, you will get a code parameter from the destination URL. Copy this.
5. Generate refresh token.
I made this separate function, but it is really just a single API call that takes as its inputs the code from the above step, your existing redirect_uri, as well as the environment variables for the Google Client ID and Client Secret. and generates a refresh token.
I recommend storing this as environment variable, as you will not need to regenerate it frequently.
6. Generate OAuth token
Another single API call here. It just takes your refresh token, Client ID, and Client Secret to generate an access token. These expire pretty quickly (defaulting to about 3600 seconds / 1 hour), so I recommend creating a separate function for this.
You can then dynamically generate tokens when need for your app.
Conclusion
Generating OAuth tokens for Google accounts was pretty challenging for me, and I had been using Zapier to handle the authentication side of things. But I decided to give it a try with Xano and eventually got it working.
This can let you do all kinds of cool things, like building Google Slides and Sheets using the API, manipulating your calendar automatically, and similar.
And if you want a super-quick walkthrough of the procedure without Xano, check out this video: