Andi Nuruljihad
Andi Nuruljihad

Reputation: 88

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. Here's a screenshot of the registration page.

Login Page

Initially, the user logs in via their existing Google account and this page is displayed. Upon clicking the button, what I want is for the script to add their submitted information and their current email to a Google Sheet. Once their info is in the Sheet, they only need to log in via Google to gain access to the system. However, when I try this with another account I get this error:

You Need Access

Is this a permissions problem? Or does Google Scripts not allow this kind of direct manipulation of files on my Drive? Here are my permissions settings for my web app:

Web App Permissions

Is this at all possible?

Upvotes: 0

Views: 438

Answers (1)

Tanaike
Tanaike

Reputation: 201358

From your question, I could understand that the settings of your Web Apps is as follows.

  • 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.

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. 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. 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.
    • 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.
    • 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.
    • 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.
    • 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.
      • When Who has access to the app: Anyone is used, it is required to share the script of new Web Apps with the user. So I proposed to use Anyone, even anonymous for this situation.
  2. When the form is submitted, the values are put to your Google Spreadsheet using this new Web Apps.
    • In this case, new Web Apps is used as the wrapper API for putting the values to Spreadsheet.

References:

Upvotes: 2

Related Questions