Reputation: 1591
I would like to programmatically create a Google Sheet using the Google Sheets API, make it public, and embed it into an IFRAME on a webpage.
I can't figure out how to make the spreadsheet visible to the public using the API. Is there a setting for this in the API when you create or update the spreadsheet?
I followed Google's Python Quickstart and was able to create and update spreadsheets.
Using the Drive API I can make the spreadsheet public, and I can access it from other accounts. However, this does not allow you to embed it in a webpage (It still states "We're sorry. This document is not published." in the frame). There must be another setting for this. Is it possible to set this with the Drive API?
FWIW here is what I was able to do to make it public (but still unable to embedd the sheet in an iframe)
SCOPES = ['https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive.metadata',
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive']
drive_client = discovery.build('drive', 'v3', http=creds.authorize(Http()))
user_permission = {
'type': 'anyone',
'role': 'reader',
}
result =drive_client.permissions().create(
fileId=sheed_id,
body=user_permission,
).execute()
Upvotes: 3
Views: 4366
Reputation: 41
For those ending up at this question while searching for a solution to the publishing of embedded content issue:
publishing files using the google drive api is possible through revisions.
SCOPES = ['https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive.metadata',
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive']
drive_client = discovery.build('drive', 'v3', http=creds.authorize(Http()))
drive_client.revisions().update(
fileId=spreadSheetId,
revisionId=1,
body={
"published": True,
"publishAuto": True,
"publishedOutsideDomain": True
}
).execute()
Depending if you want to make these available only inside or also outside of your domain, you can set these settings accordingly.
ref: https://developers.google.com/drive/api/v3/reference/revisions
Upvotes: 0
Reputation: 181745
Permissions are part of Google Drive and not specific to Spreadsheets, so you need to use the Google Drive API for that. See the reference.
Upvotes: 3