【问题标题】:Make a spreadsheet public with the Google Sheets API?使用 Google Sheets API 公开电子表格?
【发布时间】:2018-01-21 23:42:24
【问题描述】:

我想使用 Google 表格 API 以编程方式创建一个 Google 表格,将其公开,并将其嵌入网页上的 IFRAME。

我不知道如何使用 API 使电子表格对公众可见。创建或更新电子表格时,API 中是否有此设置?

我关注了Google's Python Quickstart,并能够创建和更新电子表格。

更新:

使用 Drive API,我可以公开电子表格,并且可以从其他帐户访问它。但是,这不允许您将其嵌入网页中(它仍然在框架中显示“我们很抱歉。此文档未发布。”)。为此必须有另一个设置。 是否可以使用 Drive API 进行设置?

FWIW 是我能够将其公开(但仍无法将工作表嵌入 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()

【问题讨论】:

  • 为什么需要通过 API 来做这件事?只需打开您的 Google 云端硬盘,获取永远不会更改的可共享链接,然后将其复制到任何地方
  • @cricket_007 有很多充分的理由;也许他们需要发布 1000 个,或者每天一个新的,或者......
  • @Thomas 啊,没有考虑可扩展性

标签: python google-sheets google-sheets-api google-api-python-client


【解决方案1】:

权限是 Google 云端硬盘的一部分,并非特定于电子表格,因此您需要为此使用 Google Drive API。请参阅reference

【讨论】:

  • 谢谢,我可以将其公开,但无法将其嵌入网页中。是否有其他设置可以由 API 设置?