Google Drive API with Python Part I: Set Up Credentials

Google Drive API with Python Part I: Set Up CredentialsthecruisyBlockedUnblockFollowFollowingMar 31A lot of companies are using Google Drive to manage and store some of their files so that their employees can access them easily from anywhere as long as there’s an internet access.

When I first started working with the API, I was having difficulties and only after using it a few times that I developed a better understanding.

That is why I decided to write this guide — to help you with setting up the minimum dependencies so you can start developing some workflow and automation for your companies or any projects that use Google Drive.

The guide I am writing is going to be divided into 3 x parts:Set up credentials for Google Drive APIConnect to Google Drive and search for files via Google Drive APIDownload a specific worksheet from a Google sheet via Google Drive APILet’s get you set up for your first Google Drive API project.

First, go to https://console.



com/ from your browser.

This will take you to Google Console page (just like AWS console page, if you’re familiar with it) where you can manage your API and services, IAM and admin.

Create a ProjectIf this is your first time, from the left navigation bar, go to APIs & Services > Dashboard.

It will bring you to Google API & Services Dashboard where it lists all the projects you have, if any.

But, since this is your first time, you will have no project listed.

Go on and click on CREATE.

Now, you will land on a page where you can create a new project and specify the name of it (and Organization, if you manage an organisation or else you can leave this blank).

In this example, we will name our project as First Medium Project.

Go on and click on CREATE.

Enable Google Drive APIAfter you create a new project, you will be on the below page.

You should notice that you are now in your project’s dashboard, unlike before where all you could see was a prompt to create a new project.

Now, you should see a button that says ENABLE APIS AND SERVICES.

Click on it.

It will take you to a page where you can search for an API Service that you want to enable for your project.

On the search bar, start typing Google Drive API.

As you type, the UI will change as it pulls up the APIs that match your search query.

Click on Google Drive API as it appears in the result section and then, on the Google Drive API page, click ENABLE.

Create CredentialsAfter you enable the Google Drive API, it’s time to create credentials so that you application can authenticate itself when trying to access Google Drive resources later on.

At first, it might be overwhelming to choose the type of credentials that you need.

Google has done a great job in creating a set of questions to help you figure out which credentials to create.

Just follow the instructions on the next few photos.

Set Up OAuth Consent Screen and Add API ScopeAfter you fill up the above questionnaire, Google will recommend that you application requires the OAuth client ID and before you can set this up, you need to set up OAuth consent screen.

Now, we are going to add the scope that we want our application to be able to do.

Scope is like giving permissions to our credentials which then determine what our application has access to.

For this tutorial, we need our application to be able to see, download, create, edit and delete all of your files in Google Drive.

(You can include whatever scope you would like here, best practice is to only include what your application will do).

Once finished, click the Add button and then it will take us to the previous page.

Go on and click Save.

Create Credentials: Client Secret (OAuth Client ID)Next, we are going to add our credentials so that Google can identify who our application is and what scope it has, etc.

This is known as the Client Secret.

Go on and click on Create credentials > OAuth client ID.

For this tutorial, we are going to select Other as our Application type as we will build a command line application.

But, you can choose whatever type of application you want to build.

After this step, you are going to have your Client Secret, which you can download so your application can use it to authenticate itself.

Go on and click on the Download, which is the down arrow icon.

Your client secret is a JSON file.

Rename it to client_secret.


Congratulations!.You have now enabled the Google Drive API as well as prepared the scope and credentials for your application to use later to interact with Google Drive resources.

Stay tuned!.The Part II guide is coming soon and it will cover how to connect to Google Drive via a Python application and to search for files.


. More details

Leave a Reply