简体   繁体   English

如何允许用户通过我自己的 Google Scripts Web 应用程序编辑我的表格文件?

[英]How do I allow users to edit my Sheets file via my own Google Scripts Web App?

I'm quite new Google Scripts.我是新的谷歌脚本。 I'm trying to create a web app through which users can log in (with their Gmail accounts) and modify a Google Sheet.我正在尝试创建一个 web 应用程序,用户可以通过该应用程序登录(使用他们的 Gmail 帐户)并修改 Google 表格。 Here's a screenshot of the registration page.这是注册页面的截图。

登录页面

Initially, the user logs in via their existing Google account and this page is displayed.最初,用户通过他们现有的 Google 帐户登录并显示此页面。 Upon clicking the button, what I want is for the script to add their submitted information and their current email to a Google Sheet.单击按钮后,我想要脚本将他们提交的信息和他们当前的 email 添加到 Google 表格中。 Once their info is in the Sheet, they only need to log in via Google to gain access to the system.一旦他们的信息出现在工作表中,他们只需通过 Google 登录即可访问系统。 However, when I try this with another account I get this error:但是,当我使用另一个帐户尝试此操作时,我收到此错误:

您需要访问权限

Is this a permissions problem?这是权限问题吗? Or does Google Scripts not allow this kind of direct manipulation of files on my Drive?还是 Google Scripts 不允许对我的云端硬盘上的文件进行这种直接操作? Here are my permissions settings for my web app:这是我的 web 应用程序的权限设置:

Web 应用程序权限

Is this at all possible?这是可能吗?

From your question, I could understand that the settings of your Web Apps is as follows.根据您的问题,我可以理解您的 Web 应用程序的设置如下。

  • Execute the app as: User accessing the web app
  • Who has access to the app: Anyone

For above Web Apps, you want to make users access to the Web Apps using each browser.对于上述 Web 应用程序,您想让用户使用每个浏览器访问 Web 应用程序。

Confirmation points:确认要点:

From above situation, please confirm the following points.从以上情况,请确认以下几点。 At first, I think that when the Spreadsheet you want to put the values is in each user's Google Drive, no error occurs.起初,我认为当您要放置值的电子表格在每个用户的 Google Drive 中时,不会发生错误。 So from your question, I thought that the Spreadsheet might be in your Google Drive.所以从你的问题来看,我认为电子表格可能在你的谷歌驱动器中。

  • Although I'm not sure about your whole script, if the Google Spreadsheet which is used in your script of Web Apps is in your Google Drive, it is required to shared the Google Spreadsheet with the user.虽然我不确定您的整个脚本,但如果您的 Web 应用程序脚本中使用的 Google 电子表格在您的 Google Drive 中,则需要与用户共享 Google 电子表格。 Even when the script of Web Apps is the container-bound script of the Spreadsheet and getActiveSpreadsheet() is used, it is required to share the Spreadsheet with the user.即使Web Apps的脚本是Spreadsheet的容器绑定脚本,使用getActiveSpreadsheet() ,也需要与用户共享Spreadsheet。
    • When you want to put the values to your Spreadsheet in your Google Drive when the user submitted the form, please share the Spreadsheet with the user as the writer.当您想在用户提交表单时将值放入您的 Google Drive 中的电子表格时,请与作为作者的用户共享电子表格。
    • When you want to only read the values from your Spreadsheet in your Google Drive when the user submitted the form, please share the Spreadsheet with the user as the viewer.如果您只想在用户提交表单时从 Google Drive 中的电子表格中读取值,请以查看者的身份与用户共享电子表格。
    • Also, you can publicly share.此外,您可以公开分享。 But I thought that this might not be the direction you expect.但我认为这可能不是你所期望的方向。

Other method:其他方法:

If you don't want to share the Spreadsheet with the user, how about the following workaround?如果您不想与用户共享电子表格,以下解决方法如何?

  1. Deploy new Web Apps as following settings.按照以下设置部署新的 Web 应用程序。
    • Execute the app as: Me
    • Who has access to the app: Anyone, even anonymous
      • In this case, you can also make user access to this Web Apps using a key as the query parameter.在这种情况下,您还可以使用密钥作为查询参数,让用户访问此 Web 应用程序。
      • When Who has access to the app: Anyone is used, it is required to share the script of new Web Apps with the user.Who has access to the app: Anyone ,需要与用户共享新的Web 应用程序的脚本。 So I proposed to use Anyone, even anonymous for this situation.所以我建议在这种情况下使用Anyone, even anonymous
  2. When the form is submitted, the values are put to your Google Spreadsheet using this new Web Apps.提交表单后,使用这个新的 Web 应用程序将值放入您的 Google 电子表格。
    • In this case, new Web Apps is used as the wrapper API for putting the values to Spreadsheet.在这种情况下,新的 Web 应用程序用作包装器 API 以将值放入电子表格。

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在我的Google Apps脚本/ Google表格HTML中包含脚本? - How do I include scripts in my Google Apps Script/Google Sheets HTML? 我如何允许用户将文件上传到我的网站,对其进行编辑并将其保存回去 - How do I allow the user to upload file to my site, edit it and save it back 如何在不破坏我的咕unt脚本的情况下将页面添加到yo Web应用程序? - How do I add pages to a yo web app without breaking my grunt scripts? 如何通过facebook api获取我自己网页的活跃用户 - How to get active users of my own web page via facebook api 如何在电子表格文件中的所有工作表上运行 Google Apps 脚本? - How do I run a Google Apps script on all sheets in my spreadsheet file? 如何将变量传递给我的脚本.js文件? - How do I pass a variable to my scripts .js file? 如何通过网络应用程序将 Excel 导入 Google 表格 - How to import Excel to Google Sheets via web app 如何为我自己的可视化加载这个 HTML 文件? - How do I load this HTML file for my own visualization? 如何在我的 React Hooks 电子商务应用程序中使用 JSON 文件作为虚拟用户的数据库? - How do I use a JSON file as a database for dummy users in my React Hooks e-commerce app? 如何允许用户访问我的Google API应用程序而无需对其进行身份验证? - How to allow users to access my Google API application without authenticating for it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM