Reputation: 125
I have been using this link to read spreadsheets in Python, which works perfectly well: https://predictivehacks.com/the-easiest-way-to-connect-python-with-google-sheets/
However, I noticed there isn't any implementation for it to write and push datavalues into a spreadsheet on google. I did some research on google and noticed that the alternative ways seem to be to use a service account and share the spreadsheet to the service account email so that it can access it.
Note: I have the ID of the specific spreadsheet that I want to access
Questions:
Thanks
Upvotes: 0
Views: 1715
Reputation: 5543
Use gspread library. You can use OAuth Client ID to authenticate your application in gspread.
- Enable API Access for a Project if you haven’t done it yet.
- Go to “APIs & Services > OAuth Consent Screen.” Click the button for “Configure Consent Screen” and follow the directions to give your app a name; you don’t need to fill out anything else on that screen. Click Save.
- Go to “APIs & Services > Credentials”
- Click “+ Create credentials” at the top, then select “OAuth client ID”.
- Select “Desktop app”, name the credentials and click “Create”. Click “Ok” in the “OAuth client created” popup.
- Download the credentials by clicking the Download JSON button in “OAuth 2.0 Client IDs” section.
- Move the downloaded file to ~/.config/gspread/credentials.json. Windows users should put this file to %APPDATA%\gspread\credentials.json.
For updating cells or range you can use gspread's update method:
Example:
worksheet.update('A1:B2', [[1, 2], [3, 4]])
Upvotes: 3