Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support public published spreadsheets #345

Closed

Conversation

paulfitz
Copy link
Contributor

This allows use of gspread without an authorization step when accessing public spreadsheets that have been "published to the web."

It adds a new gspread.public() alternative for creating a client. The client won't be able to access private spreadsheets.

An update to tests.config is needed to point to a published spreadsheet, some new unit tests added won't pass without that.

There's been some related discussion in #175.

@gwillem
Copy link

gwillem commented Feb 10, 2016

Thanks a lot! A lot!

@burnash
Copy link
Owner

burnash commented Jun 30, 2016

@paulfitz Thank you very much for the PR and sorry for the delay in reviewing it. This is a great feature.

The test fails for my public spreadsheet. It looks like the request in get_spreadsheets_feed() gets redirected to a Sign In page:

======================================================================
ERROR: test_properties (tests.test.PublicSpreadsheetTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "gspread/tests/test.py", line 176, in setUp
    self.spreadsheet = self.gc.open_by_key(key)
  File "gspread/gspread/client.py", line 120, in open_by_key
    raise SpreadsheetNotFound
SpreadsheetNotFound:
-------------------- >> begin captured logging << --------------------
requests.packages.urllib3.connectionpool: INFO: Starting new HTTPS connection (1): spreadsheets.google.com
requests.packages.urllib3.connectionpool: DEBUG: "GET /feeds/worksheets/1NjijBhs1syNImXr4ihnrU2xGCLFvSkN-6-ZSTe_-k6Y/public/full HTTP/1.1" 302 None
requests.packages.urllib3.connectionpool: INFO: Starting new HTTPS connection (1): www.google.com
requests.packages.urllib3.connectionpool: DEBUG: "GET /accounts/ServiceLogin?service=wise&passive=1209600&continue=https://spreadsheets.google.com/feeds/worksheets/1NjijBhs1syNImXr4ihnrU2xGCLFvSkN-6-ZSTe_-k6Y/public/full&followup=https://spreadsheets.google.com/feeds/worksheets/1NjijBhs1syNImXr4ihnrU2xGCLFvSkN-6-ZSTe_-k6Y/public/full&ltmpl=sheets HTTP/1.1" 302 542
requests.packages.urllib3.connectionpool: INFO: Starting new HTTPS connection (1): accounts.google.com
requests.packages.urllib3.connectionpool: DEBUG: "GET /ServiceLogin?service=wise&passive=1209600&continue=https%3A%2F%2Fspreadsheets.google.com%2Ffeeds%2Fworksheets%2F1NjijBhs1syNImXr4ihnrU2xGCLFvSkN-6-ZSTe_-k6Y%2Fpublic%2Ffull&followup=https%3A%2F%2Fspreadsheets.google.com%2Ffeeds%2Fworksheets%2F1NjijBhs1syNImXr4ihnrU2xGCLFvSkN-6-ZSTe_-k6Y%2Fpublic%2Ffull&ltmpl=sheets HTTP/1.1" 200 None
--------------------- >> end captured logging << ---------------------

@MTRNord
Copy link

MTRNord commented Feb 24, 2017

Any update on this? I am really interested in it.

@richiverse
Copy link

richiverse commented Feb 25, 2017 via email

@MTRNord
Copy link

MTRNord commented Feb 25, 2017

@richiverse link? or what do you mean? :)

@paulfitz paulfitz force-pushed the read_public_published_spreadsheets branch from 8a8ff05 to 1418f1f Compare February 25, 2017 16:51
@paulfitz
Copy link
Contributor Author

I've rebased this to bring it up to date. @burnash I can replicate what you see using a spreadsheet that is public but not published (in the sense of File->Publish to the web->Entire Document->Publish). Can you confirm that your test spreadsheet is published?

To be concrete, https://docs.google.com/spreadsheets/d/1F0ow6Rx7oGGy26cQO3nmI-NhwDL41CxoNz1lkaA4hQ8/edit?usp=sharing (public but unpublished) fails tests for me but https://docs.google.com/spreadsheets/d/16i5mfs194m44guNIBUylgZrvNslQlkp7F9JNbQar7E4/edit?usp=sharing (public and published) passes tests for me.

@paulfitz
Copy link
Contributor Author

paulfitz commented Mar 2, 2017

Took another quick check to see if it is possible, when logged in, to access a public non-published spreadsheet programmatically. But I can't get past a We're sorry. This document is not published message. If anyone has any leads I'd be happy to investigate further, but for now access to public published spreadsheets is the best I know how to do.

@burnash
Copy link
Owner

burnash commented Mar 3, 2017

@paulfitz Thanks for the clarification. I actually didn't know that there is this difference. Let me try again.

This allows use of gspread without an authorization step when
accessing public spreadsheets that have been "published to the web."

It adds a new gspread.public() alternative for creating a client.
The client won't be able to access private spreadsheets.
@paulfitz paulfitz force-pushed the read_public_published_spreadsheets branch from 1418f1f to 314d555 Compare August 19, 2017 02:16
@paulfitz
Copy link
Contributor Author

The branch had become a little stale so I've rebased again. I also added a concrete example of a public, published sheet in tests/tests.config.example, in case it helps, @burnash. To make such a sheet two steps are needed:

  • File -> Publish to the web -> Publish -> OK
  • Share -> Get shareable link -> Done

Neither of these steps alone is sufficient to make the sheet available without login.

@burnash
Copy link
Owner

burnash commented Oct 17, 2018

@paulfitz Thank you again for the contribution. I'm really sorry for such a late reply. API v3 has been deprecated for quite a while. I have put all of the time I had for gspread into porting it to API v4.

I'm afraid the changes in this PR are not relevant anymore. However, the idea of accessing a public spreadsheet and your instructions on how to make public spreadsheets are still relevant.

The API migration guide states that the visibility is no longer required in v4:

In the new Sheets API v4, there is no explicit declaration of visibility. API calls are made using spreadsheet IDs. If the application does not have permission to access specified spreadsheet, an error is returned. Otherwise the call proceeds.

Which is true. I followed your instructions on how to publish the spreadsheet and was able to retrieve the data from the public spreadsheet. The difference from v3 is that the client has to be authenticated.

I'm closing this pull request. I'll update the docs with the instructions on how to read public spreadsheets.

@burnash burnash closed this Oct 17, 2018
@paulfitz
Copy link
Contributor Author

Thanks @burnash, makes sense!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants