使用 Google 表格 API 制作电子表格 public?
Make a spreadsheet public with the Google Sheets API?
我想使用 Google Sheets API 以编程方式创建 Google Sheet,使其成为 public,然后将其嵌入到网页的 IFRAME 中。
我不知道如何使用 API 使 public 可见 sheet。当您创建或更新点差时,API 中是否有针对此的设置sheet?
我关注了 Google's Python Quickstart 并且能够创建和更新传播sheets。
更新:
使用驱动器API我可以进行传播sheetpublic,我可以从其他帐户访问它。但是,这不允许您将它嵌入到网页中(它仍然在框架中声明“我们很抱歉。该文档未发布。”)。为此必须有另一个设置。 是否可以使用驱动器进行设置API?
FWIW 这是我能够做到的 public(但仍然无法在 iframe 中嵌入 sheet)
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()
权限是 Google 驱动器的一部分,并不特定于电子表格,因此您需要使用 Google Drive API for that. See the reference.
对于那些在搜索嵌入式内容发布问题的解决方案时遇到这个问题的人:
通过修订可以使用 google 驱动器 api 发布文件。
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()
根据您是想让这些设置仅在您的域内还是在域外可用,您可以相应地设置这些设置。
参考:https://developers.google.com/drive/api/v3/reference/revisions
我想使用 Google Sheets API 以编程方式创建 Google Sheet,使其成为 public,然后将其嵌入到网页的 IFRAME 中。
我不知道如何使用 API 使 public 可见 sheet。当您创建或更新点差时,API 中是否有针对此的设置sheet?
我关注了 Google's Python Quickstart 并且能够创建和更新传播sheets。
更新:
使用驱动器API我可以进行传播sheetpublic,我可以从其他帐户访问它。但是,这不允许您将它嵌入到网页中(它仍然在框架中声明“我们很抱歉。该文档未发布。”)。为此必须有另一个设置。 是否可以使用驱动器进行设置API?
FWIW 这是我能够做到的 public(但仍然无法在 iframe 中嵌入 sheet)
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()
权限是 Google 驱动器的一部分,并不特定于电子表格,因此您需要使用 Google Drive API for that. See the reference.
对于那些在搜索嵌入式内容发布问题的解决方案时遇到这个问题的人:
通过修订可以使用 google 驱动器 api 发布文件。
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()
根据您是想让这些设置仅在您的域内还是在域外可用,您可以相应地设置这些设置。
参考:https://developers.google.com/drive/api/v3/reference/revisions