How to allow others to access a web app made from a Google Apps Script? - google-apps-script

I deployed a web app from a Google Apps Script, but others don't seem to be able to run it.
(It runs fine for me when logged-in to Google)
I keep getting "Request to share" email, even though I set the source script to be "Public on the Web".
"Execute the app as:" is set to "User accessing the web app".
A link to the app is at http://truevis.com/rations
It could be very useful to others, but right now I think that no one else can run it.

The link you show here is the development link , the one that is described as "the last saved version of your code", this link is not shareable ... the one you should give to people is this one :
https://script.google.com/macros/s/AKfycbz1SKJi5HW1r2ZHiYpjedjul-IE4vcB266kdDzDrVCE/exec
it is shown in this popup window
beside that, the sharing properties of the script file is not relevant, you could keep it private.... only the settings in this window are important to determine who has access to your app and how (meaning run as you or as user accessing the app).
You should also keep in mind that users will see the version you have chosen in this same popup window, no matter the changes you could have saved and are using in your .dev version... so think about publishing the right version.

What I did to get it working:
I copied the GS code to a new file, deployed as Web app, then set "Execute the app as:" "me", "Who has access to the app:" "anyone even anonymous".
https://script.google.com/macros/s/AKfycbwPtys8PE8Wda_HS9rvrdftJ0TGbCfMlT5xLlfsNFt9m5uw6qM/exec

I think once you deploy a version with certain permission, it does not work properly if you change the permission for the same version.
Creating a new version seems to solve the problem

Related

Have an issue with access to Google Web App Script

I tried to find the answer to this question. I've combed forums and stackoverflow and I'm still at a loss for how to get a web app to work outside of my own domain.
Change Admin Share Settings
I've read here and in other places go to Admin Console > Apps > Drive and Docs > Sharing Options
All the ones mentioned are checked:
"Invitations to people outside of domain who are not using a google account"
"Allow users in domain to publish files visible to the world as public or unlisted"
Publishing App
Made sure to avoid these pitfalls:
"Anyone, even anonymous"
Execute the app as "Me"
Made sure to create a new web app to avoid the caching issues
Yet I still cannot see it if not logged in as a user attached to the domain. It's just a simple "hello world" test to simplify the code, but I still get blocked. Seeing..
Any help would be greatly appreciated. Thank you to the community for all the other answers that at least put me to knowing most of the potential issue.
It turns out that I'm at fault. It's never user error, right?! You can't just copy the web URL at this stage:
You have to go to it then copy the redirected URL for anonymous access.
My redirect URL looked more like https://script.google.com/a/macros/...

Google Script ~ How to automate authorization for app?

I've made an app in Google Apps Script to use in an iframe on my site. Problem is I have to go through a bunch of steps every time someone new wants to use the app.
My goal:
What I would like to do is automate the app so it just approves anyone who authorizes it when they're initially prompted. Given that the users initial confirmation is the important part, I don't see why it would be a problem to just have the app allow them in, without them having to wait for me to confirm their confirmation.
The Breakdown:
The permissions settings for the app are as follows:
"Execute the app as:" = "User accessing the web app"
"Who has access to the app:" = "Anyone"
The user must obviously have a Google account to use this app, and they have to authorize the app before they can use it. When they do, an email gets sent to me, I have to find it, open it, and click the "Open sharing settings" link which opens the apps script file, then click "send" on the popup just to allow that one person to use the app.
Many people will be requesting authorization, and I don't want to have to check my gmail every day and manually confirm 5 or 10 new authorizations. That's way too much for me, and too much of a pain for the people using it. Despite having put almost a year into coding this thing, I'd rather not deploy it than bother with that. Yea, I definitely should've scoped this out better before coding the bulk of it.
Potential Solution:
This is a relatively naive guess, but would it work for me to make a second app that runs on a schedule, and opens the initial app's script file in an iframe, using sandbox="allow-same-origin allow-popus" attribute, then maybe use javascript to toggle "send" on the "share with others" pop-up?

Access to Web App

I have to write a small reservation web app to be used inside the company where I work. I decided to try out Google Apps Script (GAS). In short, the user must be able to select any equipment in a list and submit it along with a date he's planning to use it and his identification (this small system must implement the complete CRUD).
The environment:
Google Spreadsheet as a database
Interface made with GAS published as a Web App
The app will be accessible just to members of the company's domain, but I'm developing it in my personal account for now.
In the development environment, everything works fine. Then I deploy it as web app the project (Execute app as: Me; Who has access to the app: anyone). When anyone acess the link, I can't retrieve the user information (Session.getActiveUser().getEmail()). It always retrive the developer information (my information). If I switch the "Execute app as" to "User accessing the app", then the app can't access the spreadsheet that is making the role of the database. In the development environment this works fine.
The rest of the web app is working fine. I just wanted to get and record the identity (email) of who made de reservation in an automatic way (not by asking the user to type this information).
Do I have to setup something else before people can access it?
Thanks in advance.
[EDIT 1]: The situation changed a little bit. I made a few more tests and it seems that the deployed web app get updated just when I save it as a new version in the project. Anyway, I still can't retrieve the active user email. The Session.getActiveUser().getEmail() now returns a blank string.
[EDIT 2]: Following Sujay Phadke's answer bellow, I tried migrating the web app to the company's environment. It worked like a charm.
Juliano
It's well documented here: getActiveUser
When the webapp permissions are set as "execute as me", it seems that the returned userid string will be empty. It also depends on your specific domain permissions as mentioned there.

Google web app script keeps asking for users to sign in?

I have created my script and it works great. I have changed the sharing so anybody can view it, but it still asks users to login to their Google account to run the script.
Here is the link: My script
Currently you're web app is set to execute as User accessing the web app. This means they need to sign into a Google account to execute any of the code in your app.
You need to change this setting to: Execute the app as: Me
As well as change Who has access to the app from Anyone to Anyone even anonymous
Example:
The setting can be found by clicking on the cloud icon in the Apps Script IDE's toolbar.
Edit: Added new image to reflect proper settings.
It might be that they've updated the settings to where the least restrictive option is "Anyone" which would still require a log in. This is happening with my Google Workspace for Education account.

Cannot find a Google App Script I deployed as a web app

How can I find a Google App Script web app I deployed and modify it? It does not appear in my drive. Perhaps I didn't save it. Does it persist or disappear eventually? Is there somewhere that list all deployed web apps? If so, I have been unable to find it.
If your webapp is recent, simply replace "exec" at the end of the url with "edit" (without quotes) and you'll get the script editor opened on your script.
(Very old webapp have a different structure but it changed quite a long time ago so I guess you're not concerned with that.)
No. There is nothing like deployed webapps list. if u didn't save, u can't get it back even though you had deployed it. Make a try to open that script with the url available in your browser's history.