简体   繁体   中英

Uploading data values to google sheets without service account? PYTHON

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

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM