Using Google Script in shared, restricted spreadsheets - google-apps-script

I wrote a script for a google spreadheet which is run by clicking on an image embedded in the spreadsheet.
Everybody with the link to the spreadsheet can edit it (except some areas with formulas etc. which are protected).
When I'm logged in with my google account, everything works fine, but when I log out and try using the spreadsheet like a "normal" user, nothing happens when I hit the image.
I didn't find anything in the options regarding "script sharing" etc.
Would be awesome if someone could give me a hint (I'm quite new to google script...).
Thanks for your answers!
Vincent

Anonymous users can't run scripts. By design. Protected ranges, sharing and all the rest of it have nothing to do with your problem.
The user - whoever they happen to be - must be logged in to run any script. Scripts will simply be ignored for anonymous users.
So the solution in your case is to tell all your users that they must log in before being able to run a script.

Related

Can an apps script macro in a Google sheet be used by other users?

I have a fairly simple requirement for a Google sheets apps macro script - it basically pulls the values from a couple of cells in another sheet and displays them in an alert box.
I've done the macro for this and it works fine. What I now want is for anyone I've shared the sheet with to be able to run the same macro. This is where things have suddenly got a bit more involved! My questions are:
Is this possible? And if so, what's the best way of achieveing it? At the moment, the macro is not available for the test user I've shared the sheet with. I've had a bit of a look around and it seems like publishing the script as a web app may be the way to go - can anyone confirm if that is correct? Or would there be a better option? I don't know anything about web apps so just want to confirm if this is the best option before trying to wrap my head around it all.
If the sheet in question has been shared with a user, but the second sheet which the script pulls data from has not, is it still possible for the user to run the script and retrieve the data? Or would the second sheet need to be shared with that same user as well? (If it would then it kinda defeats the object of what I'm trying to achieve).
Finally, would the user with whom the sheet is shared have to have a Google account in order to do this? I'm assuming so...which is a bit of a pain, but I guess understandable.
Thanks very much
Wokaround
Following the requirements you have described I get that you want your users to trigger an Apps Script function that will alter or get data from your Spreadsheet while only granting your users viewer-only acccess.
As described here only users with editor level access can run functions on your bounded script or activate it when clicking a button in your Spreadsheet.
To overcome this you can create a simple web app with a button that will trigger your function. Users will have to access this web app to trigger the function. The good point is that they will not have editor level access to the Spreadsheet nor to the actual script of the web app (as they will just interact with its user interface).
The web app would be a different script that can interface any of your Spreadsheets editing them or getting any information from them.

Google Script and Anonymous user in Google Sheet

I've a public Google Sheet (everyone can access it and edit it). In it, I use a script, a function, that download a csv with the UrlFetchApp.fetch(url);.
When an anonymous user access it (without the google login), the user can view, and edit the sheet, but, the user cannot run the script. The user must be logged with a google account to the script do the working.
The stranger thing is that this sheet with this script was working for anonymous users early. This problem didn't occur before a couple weeks ago.
Do you know if the google change something about security or is it an error that I am doing?
In order to run apps script on a particular user's behalf, Google Workspace requires that user's permission, via an OAuth flow.
If a user is anonymous therefore, you can see why this permission cannot be granted, which is why the script won't work for those users.
I guess it is an intended behavior as long as the anonymous user access the sheet via shareable link. As stated in this support page, you might see a name you don’t recognize or "anonymous animals" viewing your document, spreadsheet, or presentation. This can happen when a document is shared publicly or with anyone who has the link.
Limit how people can view your file
If you want to stop sharing a file you can edit, you can learn how to:
Turn off link sharing for a file.
Prevent others from sharing files you own.
Hope this helps.

Is there any reason a Google Apps Script wouldn't run for specific people?

So here's my problem: I've made a Google Apps Script that I've put on an HTML page to make a form. The script then pushes the data to a Google Sheets document that is accessible to anyone, even anonymous. However, the only person the script won't run for is the script administrator. I've tried with many different computers, and mine was the only one which didn't run.
I've also cleared my cache, and checked to see if the source code showed the correct script destination, and sure enough, it did. Is there anything that I've been doing wrong?
Thanks for the help, guys.
If you are using a script to make a form, it may be better to just use a Google Form and then link it to a spreadsheet. Then if you want to add a script into the spreadsheet, you can go in tools and then scripts, put in script code, and put appropriate triggers for when you want the script to run. Google Form submissions can be anonymous as well and you'll be able to set the privacy of that spreadsheet to anyone with link. You can choose in the form settings to show the option to view submissions after submitting form.

I can't find a Google Script I created (that is not attached to a spreadsheet)

I am having trouble finding a saved script. I followed this post to create a script that schedules email deletion, and I believe I saved it, but searched for it in Drive to no avail. The script is still running because emails are being deleted.
Things I've tried
I've read other posts that mention tracking down the spreadsheet that a script is attached to, but I didn't create a spreadsheet (unless scripts are all mysteriously attached to a spreadsheet).
I searched Drive.
I attempted to visit script.google.com while signed into my account. It said that I need permission and that I need to ask the owner for access. This is a work account managed by Google Apps. I asked my admin and he can't access script.google.com either. The only thing I can think of that's worth mentioning is that we changed domains at one point, but I can't see how that would affect ownership or permission.
So, two questions really:
Where is the script?
Who is the owner of the account?
Any help would be appreciated.
Don't know if it helps but you can try by accessing this link:
https://drive.google.com/drive/u/0/search?q=type:script
Also if you have a google apps account recheck with the admin if he has given you access.
Recheck your permissions at:
https://security.google.com/settings/security/permissions?pli=1
In there you can try to find the script if you ever ran it using your account.
Also might worth to take a look into this dev article:
https://developers.google.com/apps-script/guides/services/authorization#authorization_lifecycle_for_add-ons
Hope it helps!
You can also try visiting the Google Dashbboard at:
https://script.google.com/home/
This is another link to try in Google Drive, which will find all files in your Drive of type script, and restrict to those owned by you.
https://drive.google.com/drive/u/0/search?q=type:script%20owner:me

Permission to run a site-script

In my organizzation, I created an internal site with a script callable from different pages inside that reads / writes data from various spreadsheets and send mail.
For testing, I shared the site and documents with a my colleague but he can't run the scripts because appears page to request permission:
"... This script is Requesting permission to do potentially harmful operations. Only authorize the script if you truly trust the author!"
if my colleague click on "authorize" nothing happens.
I give to my colleague the link of the script (not the page that embeds the script), clicking on "authorize" he received a long email from google where it is explained that authorized the execution of the script but instead continues to not work ..
The one way to allow the execution of script is to run the script directly from the editor to grant permissions.
I can't do it for other colleagues!!!
I'm really unhappy about this. I worked a lot on the script but now I realize that I can't do it to my colleagues for another google's big bug.
I have a script that uses also spreadsheet and mail service and I have not any difficulties with authorizations ...(after the red screen is approved user have full access to the app)
Are you sure there is not something else that could prevent your script to work with other users ? A document that is not shared or a call to an external api or whatever ? All I can say is that the current procedure is far more convenient than it used to be a few month ago and that I see not bug on that just now...
In my experience with scripts in spreadsheets, new users have to run the script, authorize it, and run it again.