πUsing Google API (drive & spreadsheet)
Last updated
Last updated
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.
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.json
The 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_email
β value 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.