How to add Google Drive Scripts project into Googl

2019-08-12 07:30发布

问题:

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

回答1:

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 :



回答2:

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'



回答3:

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.