0

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:

  • I'm working with this issue and sharing it to a google service account email doesn't seem to be an option for me. I was wondering if anyone know a way where I can work around this issue.

Thanks

1 Answer 1

3

Use gspread library. You can use OAuth Client ID to authenticate your application in gspread.

  1. Enable API Access for a Project if you haven’t done it yet.
  2. 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.
  3. Go to “APIs & Services > Credentials”
  4. Click “+ Create credentials” at the top, then select “OAuth client ID”.
  5. Select “Desktop app”, name the credentials and click “Create”. Click “Ok” in the “OAuth client created” popup.
  6. Download the credentials by clicking the Download JSON button in “OAuth 2.0 Client IDs” section.
  7. 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]]) 

References:

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. I tried the following but after authenticating, I am getting this error. ValueError: check_hostname requires server_hostname
Kindly include code snippet and stack trace in your post above
Actually, I forgot to refresh my kernel back then. Now everything works perfectly. And also, when the popup asks me to confirm the authentication, is this a one-time thing?
@mathgeek - Yes that is a one time thing.
Great awesome, thank you for your help! Appreciate it and upvoted :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.