You are currently viewing the new Anvil Editor Docs.
Switch to the Classic Editor Docs
You are currently viewing the Classic Editor Docs.
Switch to the new Anvil Editor Docs

Connecting Google to Anvil

For advanced use of Anvil’s Google integration, you need to let Google Developer Console know about your app.

If you want to do either of these things:

  • Access users’ own Google Drive files from your app
  • Use Google’s REST APIs from Anvil

You need to configure some credentials using Google Developer Console.

This Google support answer describes the basic process. We’ll go through it in more detail in the following sections.

Create a Project

Open Google Developer Console. Create a project or select an existing project.

The top bar of the Google Developer Console, with the project selection dropdown circled

Then select ‘APIs and services’ from the hamburger menu:

The hamburger menu of the Google Developer Console, showing options including 'APIs and Services'

Select ‘Credentials’:

The side navbar of the Google Developer Console, with Credentials highlighted

First, you need to set up an OAuth consent screen. Then, you can create an OAuth Client ID that allows your Anvil app to identify your Google project.

Click on ‘OAuth consent screen’. This is where you set up the screen that your users will see to give your app certain permissions on their Google account. You’ve probably seen this sort of screen before when using a new app, it will say something like “App X would like to: use your location”.

The first part of this form is pretty self-explanatory; keep the application type as ‘Public’ and set your application name and logo as appropriate.

The top of the OAuth Consent screen, where you can add an application name and logo.

The ‘Scopes for Google APIs’ section allows you to list the permissions to request from the user. If you want to access your users’ Google Drive files, you will need to add ../auth/drive.file.

The scopes list with ../auth/drive.file added to it.

In the ‘Authorised domains’ section, add any domains your app will be running under. This may be for running your app in the editor, for the live version, or your own domain if you’re using a Custom Domain.

The Authorised Domains list with added to it.

Create an OAuth Client ID

Click on ‘Credentials’, then ‘Create Credentials’ and select OAuth Client ID:

The Credentials view in Google Developer Console - OAuth Client ID selected from the Create Credentials dropdown.

You’re given a list of application types - choose ‘Web application’:

The first part of the Create OAuth Client ID form. The application type 'web application' is selected.

Now enter in ‘Authorised redirect URIs’. Be sure to press enter in this box so that it gets added to the list - it will look like this:

The Authorised Redirect URIs list with the Anvil client_auth_callback URI added.

Hit ‘create’ and you will be shown the client ID and secret:

Google Developer Console modal stating that an OAuth client has been created and giving the client ID and secret.

Now go to your Anvil app and open the Google API Service. Paste the client ID and secret into the boxes in the “Access your users’ Google Drive files” section:

Google API Service view in Anvil showing the Client ID and Secret pasted in to the 'Access your users' Google Drive files' section.

Google API Service view in Anvil showing the Client ID and Secret pasted in to the 'Access your users' Google Drive files' section.

Test that it works

You should now be able to use any Google REST APIs you have requested scopes for. If you have requested the ../auth/drive.file scope, you can run this code to log someone in with their Google account read the names of their Google Drive files (after they give their permission):

  folder =

  for f in folder.list_files():

If this works, you’ve correctly set up Anvil to access your Users’ Google Drive files and use Google REST APIs.

Next up

Now that you’ve configured Google Developer Console, you can use some of the advanced features of Anvil’s Google integration.

Access your users’ Google Drive files

Anvil has a built-in Python API for accessing your users’ Google Drive files.

Access Google REST APIs

You can access any of Google’s REST APIs from client or server code using Anvil’s anvil.http.request function.

Do you still have questions?

Our Community Forum is full of helpful information and Anvil experts.