burnash / gspread

Google Sheets Python API

Home Page:https://docs.gspread.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible to have an anonymous session with a "public" document

dansteingart opened this issue · comments

Is there anyone to instantiate a client without "logging" in, for example if the shared sheet is publicly viewable?

TIA.

HI,

Since gspread is such an amazing solution to access google spreadsheets, I would like to use it. In my case I need to deal with a publicly available spreadsheet. I did not find the way to do so (not very fluent in python :-( ) In any case, is this possible?

I'm afraid at the moment it's not possible (due to Google API restrictions.)

Hi @burnash,

I don't think this is true. Here is a very short example which returns a spreadsheet's worksheet's titles using gdata. Note, that I received the correct output for the 'published_to_the_web' key, but the 'public_on_the_web' key threw an error. See this StackOverflow post for more information.

Using gspread, any attempts to view a public document, even while logged in, threw a SpreadsheetNotFound error. I had to explicitly click the link to add the document to "My Drive" in order to access it via gspread. As evidenced by this gdata example, that should not be necessary.

from gdata.spreadsheet.service import SpreadsheetsService

published_to_the_web = '1P_DNfuhcbbpR0hJ7_zaXLRRcFr3fq-07_Nu3EhSuRTg'
public_on_the_web = '1h3xza_Tw_BAm8DZxoe2lP0PDkFDmUiFmvDeYxAn6SKE'

client = SpreadsheetsService()
feed = client.GetWorksheetsFeed(published_to_the_web, visibility='public', projection='basic')

for sheet in feed.entry:
  print sheet.title.text

I'll vouch for @MikeOrtiz being correct; this should be possible. Here's a bare URL example, in case it helps anyone unfamiliar with gdata.

https://spreadsheets.google.com/feeds/list/<spreadsheet_key>/<worksheet_id>/public/basic

This will include all the cells' data in a worksheet, without needing any authentication, as long as the containing spreadsheet is "published to the web" via File -> Publish to the web.

This is dependent on #145

Like for #145 , tested it and it works now. Closing this issue.

commented

Does anyone have an example of how to create a gspread.client.Client without authentification? Or is there a way to access to create a Spreadsheet without a client?