📊Using Google API (drive & spreadsheet)

In order to be able to use Google Sheets or Drive API, you must first authenticate yourself with the service. All Google APIs use the OAuth 2.0 protocol for authentication and authorization, which simplifies the process. Moreover, you can also create a service account that can be used to access all of Google’s resources.

Setting up

Enable the Google Sheets API

  • Go to the Google APIs Console

    Click “Select a project” in the top-right corner

  • Click the “New Project” option

  • Give a unique name to your project and click “Create”

  • Go to the APIs dashboard

    Search for “Google Sheets API” and click on it

  • Click “Enable” and wait for the API to be enabled

Create a Service Account

  • When the API is enabled, move to the Credentials page

    Click the “Create credentials” option and select “Service Account

  • Give a name to the service account and click “Create”

  • Click “Select a role” => “Project” => “Editor”

  • Click “Done”

    Now that your service account has been created, you will have to create a key, which will allow you to connect to the API automatically via this service account.

Create a Service Key

  • In the Credentials page, click on your service account name

  • Go to “Keys

  • Select “Add Key” => “Create new key”

  • Leave the option as JSON and click “Create”

  • Rename the downloaded file to client_secret.jsonThe file contains all the sensitive information that will allow your app to authenticate with Google and have access to the API. It’s critical for this file to be kept private so that only your application has access to it. The file will look like this:

    Find the client_emailvalue and copy the email address. Each spreadsheet that you want to be manipulated by your app must provide access to this email.

Share your spreadsheet with client email

  • Click “Share” in the top-right corner of your spreadsheet.

  • Use client_email from the client_secret.json. Give Editor right. Click "Send".

Now your service account has Edit access to the sheet and your application can use Google Sheets API to access the spreadsheet.

Last updated