๐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
Click the โNew Projectโ option
Give a unique name to your project and click โCreateโ
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 theclient_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