How to get the Google APIs Keys to use Google Sheet.

Victor Fernandez
5 min readApr 8, 2022
Photo by Rajeshwar Bachu on Unsplash

I wanted to use Google Sheets to display the result of some APIs requests, but to be able to do it, I needed to set up Google Workspace.

Google Cloud Platform

To use the API, I need the API token or key.

These are the steps I followed:

  1. Create a new project and enable the API.
  2. Define the type of authentication.
  3. Definition of Scope and Credentials.

1. Create a new project and enable API

Photo by Gabriel Heinzer on Unsplash

Create an account Google Cloud Platform

Navigate to console.cloud.google.com.

The first step will be to set up the Google Cloud Platform.

  • Accept the terms of services.
  • Access to the Google Cloud Platform Dashboard.

Set up a project

To get an access token or the API key, first, it is necessary to have a project.
The projects will represent the application making the request.

On the Basic account or free account, there is a limit on the number of projects. However, the number of projects slots available initially is pretty generous.

New project

First, I start by giving a name to the project and adding the organization.

Once created, the project information is in the dashboard. It can be accessed on the top bar, next to the “google cloud platform” title.

I want the Sheets API then, I used it as an example here, but the process is similar for most of the APIs.

Google provides an extensive explanation of the configuration of Authorization and authentication. I am not building a commercial application, so I skip the details regarding this section.

For integrations with a commercial goal, I strongly suggest reading about Authorization and authentication.

API & Services

With the project already set up, the next step is to add the library need it.

API & Services > Library.

Here Google listed all the APIs available.

Once the library is selected, the dashboard will display the information related to the usage of the API.

The next step is the creation of the actual credential to access the Google services and the API.

Credentials

The steps to create the credential file will include answering some questions to determine the credential type.

Next, I set the service account name, a service account, and a service account description.

2. Define the type of authentication.

Photo by Markus Spiske on Unsplash

The credentials are needed to be able to interact with the services.

The creation of the credentials.json file follows a similar process already executed with the project creation.

The resulting file will have a different name. I renamed it credentials.json It is easier to handle in future programs..

To start the process, click on + Create credentials and select the option OAuth client ID.

Consent Screen

If the “consent screen” was not configured before, google will redirect to the consent screen before generating the OAuth file.

I selected External, and I proceeded to the configuration of the consent screen.

3. Definition of Scope and Credentials.

Photo by Dose Media on Unsplash

Now, the following step is the definition of the scope of the OAuth Client.

The scope will limit the access or the actions the client can perform in the service.

I want to create, edit and delete Spreadsheets or sheets, so I needed the scope to reflect this intention.

OAuth 2.0 Client

If the “consent screen” is already configured, the configuration of the OAuth Client ID will include the application type and a name.
I wanted to use the Google API with a desktop API, so the application type selected was a Desktop App.

After clicking on the button “Create” a modal view with the information about the client authentification is displayed. This information will be in the credentials.json file

The credential file then can be downloaded, in the section called “OAuth 2.0 Client IDs

This JSON file will be used on the application as part of the authentication before any request.

And that was it, I got the credentials file, and now I have what I need to use the google spreadsheet.

Victor Fernandez

--

--

Victor Fernandez

I’m Victor, I’m a Field Application Engineer for a CCTV manufacturer. I love Raspberry Pi, Python, and Microcontrollers and I write about my personal projects.