How to add Google Drive Scripts project into Google Sites? - google-apps-script

I want to embed Google Drive Scripts/ project from Google Sites but I can not.
Google Sites alert me with a message
This url is not recognised as a valid Apps Script
after I
created project-script from Google Drive,
added a function function doget(e) { code; code; code; ... },
published the script ("Deploy as web app"),
retrieved the link link (e.g: https://script.google.com…1DkWAQ/exec), and
in the Google Sites page,
I edited page and inserted a script from menu: Insert > Apps Script Gadget.
In the next page I enter script's link but a message box shows up: "This url is not recognised as a valid Apps Script"
Where I am wrong?
My question is: Can I execute Google Drive Script without adding code in site's page? Is it possible to execute from several Google Sites' pages a Google Drive Script with different parameters?
Thanks,
Michele

The url is different when embedded in a Google site, here is an example that can be inserted :
`https://sites.google.com/macros/exec?service=keyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
You can pick the key in the standalone url.
I must admit that the interface is not really clear about that, nor is the documentation
EDIT : since some people seems to be sceptic ;-) here is an example with a shared script written as a script file :
the url given for a standalone app is :
https://script.google.com/macros/s/AKfycbxlPTVLSLfO3d1w2vSrMzzh57p9DJM6ivCIHiIfTB2AKqubSs1L/exec
The same script in the site page is :
https://sites.google.com/macros/exec?service=AKfycbxlPTVLSLfO3d1w2vSrMzzh57p9DJM6ivCIHiIfTB2AKqubSs1L
feel free to check ;-)
in the gadget properties it shows up like this :

I believe this summarizes the correct format for URLs of scripts saved on Drive for inserting with a Script Gadget on Google Sites:
Regular Google user:
https://sites.google.com/macros/exec?service=KEY
Google Apps domain:
https://sites.google.com/a/macros/MYDOMAIN/exec?service=KEY
Note the domain part is 'sites.google.com' not 'script.google.com'

As my experiences, you can't create an Apps script in Google Drive and then embed it in Sites.
To do that, log into your site's dashboard. You can do that by selecting menu item More > Manage site from your site (with logged in account). Then select tab Apps Scripts, hit the button Add new script. From there you can code your script. When you're done, come back to your site, edit a page and insert that script into your page.

Related

Add/Remove editors in Google sites using Google Apps Script

I am writing a google apps script to process bulk add/remove editors for some new Google Sites.
I am aware that google apps script currently doesn't support new google sites so I am trying to use DriveApp to manage the editors.
However the script doesn't work and returns the following:
Exception: Service error: Drive
whenever file.addEditor() or file.removeEditor() is used. I guess this just doesn't work for new Google Sites.
Are there other workarounds?
Make sure you're using the correct FileId with Sites as it's not quite as simple to acquire compared to other file types on Google Drive. When you're editing a Site page, the FileId can be found in the URL between /d/ and /p/.
Example: https://sites.google.com/d/????? this the file id ?????/p/!!!! not here !!!!/edit
I just successfully ran the below code to add/remove editors of a new Google Site.
const zFile= DriveApp.getFileById("????? this the file id ?????");
function addEditor(){
zFile.addEditor("pgsystemtester#gmail.com");
}
function removeEditor(){
zFile.removeEditor("pgsystemtester#gmail.com");
}

Embed Google Drive in Google Site

I am developing a Google Site that display different kinds of Data and soon integrating with files that is connected in Google Drive and this is where my question goes. As far as I know to import a Google Drive by doing this.
Selected Google Site > Edit > Insert > Then Select a Folder
and by that a list of files in my selected folder will display in my site in List View
Thats one solution for me. However I want also to integrate search function like a textbox below that gadget and when i search on that list of files will also show. How can I achieved that?
and also in addition how can I embed the search fucntion of Google search on that? For example I search test it will just not display the file that has a name of test but also files that contains test
any means of help is highly appreciated. TYSM
Try using Apps Script and deploying it as a web app then embedding it in your Google Site. According to the document:
Web apps can also be embedded in Google Sites. (These embedded web apps are sometimes called Google Sites Gadgets.)
To create a script that is bound to Google Sites, visit your site, click the gear icon, then select Manage site. Click Google Apps Scripts, then Add new script. After that, the process is the same as for creating and deploying a web app as above.
For the searching purposes use the field fullText which will check the Full text of the file including name, description, content, and indexable text. See Search for Files documents for further information
folder.searchFiles('fullText contains "' + search + '"')
Useful reference:
Search Google Drive folder from Google Site using Apps Script
Hope this helps.

How do I access my app scripts?

I work for a university which uses Google App for EDU. Recently, I decided to begin testing app script to see how it could be of use to our organization. I have been able to create new app scripts and run them without issue. However, I have found that once I close the browser editor tab, I am not able to retrieve any script I've wrote unless I have the editor url saved (ie. I dont see any of my script in my google drive). Is there a particular app script site where my scripts are listed?
Thanks,
Bryan
The long method i use to get to see all my App Scripts is:
open an existing spreadsheet, or simply create a new spreadsheet
go to Extensions > Apps Script
click on the "Apps Script" logo in the top left corner
This will take you to: https://script.google.com/home
The short method is just to have that link (above) saved on browser toolbar and click it whenever i need to.
to be able to starts new script from the drive you have to connect script app to your drive using the Browser interface like below :
from the connect more apps at the bottom search for "script" and add it.
If you created scripts from inside a spreadsheet, they are tied to that sheet and will not show up in Drive; you can find them via the "Script Manager" menu in that spreadsheet.
All standalone scripts will be visible in your Google Drive. Did you write your script inside a spreadsheet or a Google Site ? If so, you have to open the spreadsheet or site to see your script.
If you indeed have a standalone script, make sure you click the 'All Items' on the left hand side of Google Drive or use search.
If you've created a new script from script.google.com and have saved it, it'll appear in Drive under the root My Drive folder.
If you created one from inside of Drive by clicking the red Create button then Script, it'll be in the folder which you last clicked on before clicking Create. If you don't remember what folder you created the script file under, click the Recent folder name to find it.
If you've started one inside a Form , Sheet, or Doc you'll have to remember where the Form, Sheet or Doc was located in Drive.
You can search all your scripts in Google Drive using app:"Google Apps Script" or by selecting Google Apps Script under Opens With from the drop down menu.
As pointed out by #Mandy, this assumes you have added Apps Script as a connect app. See answer from #Serge on how to do that.
Try the handy dashboard/central location for scripts:
https://script.google.com

"Embedding Google DocList in a Google Site" Script failing

The following script was recommended to use a List Page to show a Google Docs folder on a page in a google site.
https://developers.google.com/apps-script/articles/embedding_docslist_in_sites#section2
When I try to run it on a recently created folder in Google Drive, the script never seems to finish.
The script still works for a folder created before the switch to google drive, which has a much longer ID.
What am I missing?
Cheers
In the script gallery (open a spreadsheet, click on menu Tools>Script Gallery), search for "Embed Google Docs Folders in a Google Site".
This is an updated version of the script available in the Apps Script documentation. It should work better.

Inserting published apps script from a spreadsheet to page has stopped working

I have been publishing scripts from spreadsheets, grabbing the url, pasting it into the insert apps script gadget dialog, and changing the "docs" to "sites" for a while now and has been very successful except for today. Did something change between GAS, Google Spreadsheet, and Google Sites that stopped this process recently?
Update 6/18/12
In response to comment:
Based on Peter's comment, the url change did affect the process. But the change is not specific to the issue posted here. All of the discussion has urls based on "sites" only, and does not discuss published urls from spreadsheets that contain "docs" which does not work with the Apps Script Gadget. The process posted in the question is not a stable process which in turn could not be reliable if there was a change. So a new "workaround" may need to be found in order to use Apps Scripts from spreadsheets as a service on Google Sites.
Really Published Spreadsheet Script Urls should work with Google Sites just as the Google Sites Scripts Urls do.
This may be related to a recent change in the URL format. Please star this open issue for updates.