从 google 个站点获取 app_id

Get app_id from google sites

我想通过脚本授予对我的站点的访问权限,对于 google 文档,我可以从 url 获取 ID:https://docs.google.com/document/d//编辑
并执行此操作:DriveApp.getFileById('').addViewer(emailid);

但对于 google 站点,我改为采用这种格式:
https://sites.google.com/d//p//edit
我尝试使用 id_1 和 id_2,但两者都不起作用。

谁能帮帮我?

谢谢

用于 Google 个站点的正确文件 ID 是 。 您无法向站点添加查看者的原因是,与 Google Docs 不同,Google Sites 没有查看者共享选项。相反,它使用 published viewer option.

示例:3 个具有不同访问权限的用户 (在此示例中我使用了新的 Google 站点)

示例代码:

function myFunction() {
  Logger.log(DriveApp.getFileById('id_1').getViewers());
  Logger.log(DriveApp.getFileById('id_1').getEditors());
}

日志:

[21-01-07 00:52:50:404 HKT] []
[21-01-07 00:52:50:719 HKT] [DriveUser]

如果要为 Google 站点设置查看器,可以对经典站点使用 Sites Service in Apps Script. However, you can only use Site.addViewer(emailAddress)

Note: A rebuilt version of Sites was launched on November 22, 2016. Apps Script cannot currently access or modify Sites made with this version, but script can still access classic Sites.

(更新)

目前,没有其他选项可以通过 Apps 脚本或 API 更新 Google 站点。

基于此参考:When will available the API Google Site?

Google Sites 的新版本目前不提供 API,但 Google 已宣布 API 功能,包括 Google Apps 脚本集成将可用。

有关详细信息,请参阅 Deprecation Timeline - classic Google Sites

Google doesn't offer dates for when features will be available so you won't find one.