Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set "publish to web" in Google spreadsheet using Drive python API

I'm trying to simulate clicking "publish to web" -> "start publishing now" in Google docs using the Python version of the Google Drive API. Based on my vague understanding of the documentation, I believe this should work:

service.revisions().update(fileId = newfile['id'],
    revisionId='head', body={'published':True, 'publishAuto': True})

However, this appears to have no effect on my document.

I'd like to be able to programmatically create a Google spreadsheet that is immediately world-accessible.

like image 262
David Eads Avatar asked Jan 08 '13 20:01

David Eads


People also ask

Can you publish a Google sheet to the Web?

Publish a file to the webIn Google Drive, open your file. Publish to the web. For spreadsheets, select the entire spreadsheet or individual sheets. For presentations, choose how quickly to advance the slides.

Can Google Sheets pull data from an API?

The Google Sheets API lets you read, write, and format Google Sheets data with your preferred programming language, including Java, JavaScript, and Python.

How do you publish an interactive Google sheet?

Open a file in Google Docs or Sheets that you've already published to the web. Click File. Share. Publish to web.


1 Answers

Turns out the response object that's returned by the code snippet above needs to call execute():

service.revisions().update(fileId = newfile['id'], revisionId='head',
    body={'published':True, 'publishAuto': True}).execute()

This returns a revision object and sets the publish properties on the document.

like image 130
David Eads Avatar answered Oct 19 '22 20:10

David Eads