简体   繁体   中英

Using gspread to read from a Google Drive Spreadsheet without logging in

I'm using the module gspread to (attempt) to parse a specific spreadsheet on my Google Drive. However, I eventually want to turn this project into a web application, so naturally I don't want to give away my login information. However, since I only need to read the spreadsheet, shouldn't there be a way to use gspread to read the contents of the file without having to log in? I've tried:

gc = gspread.Client(None)
sheet = gc.open_by_key(KEY)

But this fails with the error

(<class 'xml.etree.ElementTree.ParseError'>, ParseError(ExpatError('no element found: line 1, column 0',),), None)

How can I achieve this?

To be honest I don't know what the error is coming from. Pasting more of the stack trace and some additional parts of your code might help.

Anyway, as you mentioned yourself you prefer to not use your login information (email/password).

GSpread also offers to log in by using gspread.Client(auth, http_session=None) , where the auth parameter is OAuth2 credential object. Credential objects are those created by the oauth2client library .

I found this link very helpful to get the hang of it and getting it up working.

You won't log in anymore with your account, which is good, instead it will obtain OAuth 2.0 client credentials from the Google Developers Console. Then your client application requests an access token from the Google Authorization Server, extracts a token from the response, and sends the token to the Google API that you want to access.

Have you made your spreadsheet public to the web? With that you can do what you want, I've posted code samples Here Loading a generic Google Spreadsheet in Pandas

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