I have a single Google Script that I have developed, yet it is a single script that should be placed on several Google Sites pages, I would like to be able to know using the script which website has loaded my script.
How can the script identify which page has loaded it?
On a web app inserted as gadget on Google Sites, to get the name of the site we could use getActiveSite() to get the Site object representing the active site and then getName(), something like the following:
var mySite = SiteApp.getActiveSite();
var mySiteName = mySite.getName();
Related
I tried all methods available in the Google Sites API, examples
var site = SitesApp.getSite("example.com", "mysite");
the above method returns an empty array.
And the bellow method returns an error with "Invalid argument: url "
var site = SitesApp.getSiteByUrl("https://sites.google.com/domain/testweb");
How to read a Google Site properly using Google App Script ?
Details:
I own the site and the site is a new Google site NOT a classic one.
As written in the documentation,
A rebuilt version of Sites was launched on November 22, 2016. Apps Script cannot currently access or modify Sites made with this version, but script can still access classic Sites.
So, you cannot access new sites with apps script.
Users who want to access new sites through apps script can add a star(★ on top left) to this feature request to let Google know you're interested and for Google to prioritize the issue.
I have a Python cron job that pulls urls from sheet1 and populates sheet2 with scraped data from each url. Sheet 2 consists of [url, title, body, image urls]
I have an Old Google Site where I manually take sheet2's contents and create a new post. I want to automate this.
Structurally speaking would Google Scripts be able to pull and publish this dynamically? Lets say every time Sheet2 is updated (or a set interval).
I've worked with gscripts but never touched Google Sites before today.
The answer is probably yes. Apps script can do this. You have a couple of options.
Old Google sites
Option 1
Embed an apps script into the site as an iframe and stream you posts in that.
Option 2
Use either a standalone apps script or one attached to the google site and update the site using the Google Sites API.
New Google sites
Currently there is no apps script API for the new google sites. But you can embed JS HTML etc as a frame in the new sites. You can even use CDN libraries. Which means you can pull data from your sheet using something like AJAX.
Custom built option
The Google Sites API can be accessed anywhere you can handle Oauth. This means you can update Google Site from server-side code or from any client if you can handle Oauth.
This is related to a question I have posted previously.
I have a batch of CSV files that contain a data set obtained from an issue tracker tool. These I've uploaded to google drive and are presented as charts and lists from a google site.
This works reasonable well as all I now have to do is update the files in google drive and the site is automatically updated.
The displayed charts work well, but I want to present the lists as an HTML table (as opposed to an embedded sheet).
An app script seems the most logical way to do this. However, in order to do this, I need to provide the URL of the sheet containing the data to the app script. This is proving to be more difficult than I anticipated.
I attempted passing the data source as a parameter by directly linking the app script URL (xxxxxx/exec?source=yyyy), but the app script gadget in google sites doesn't pass through parameters.
I attempted to embed the script URL (with parameters) within an iframe - as suggested elsewhere, but without any luck.
Has anyone got any suggestions? Thanks.
Google Apps Script gadget can't include parameters in the gadget settings, instead, add the parameters to the links to the Google Site page
https://sites.google.com/sites/mysite/mypage?par1=A&par2=B
Regarding having several instance of the same Google Apps Script gadget that could be a problem. I think that the better way to proceed is to make copies of your script and make a different set of parameters for each one.
Step by step
Create a site
Create a script
Add the gs code
In this case the code create a template from a file that has a printlet that shows the Hellow World! if the URL parameter message is equal to true, otherwise it you show undefined.
function doGet(e) {
var template = HtmlService.createTemplateFromFile('Index');
if(e.parameter.message === 'true') template.message = 'Hello World!';
var output = template.evaluate();
return output;
}
Create a HTML file and add the HTML code
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<p><strong>Message:</strong> <?!=message?></p>
</body>
</html>
Publish your web app
Create a page
Insert a Google Apps Script gadget
Save the page
Write the page URL and the required parameters in the browser address box or in a link
https://sites.google.com/a/rubenrivera.mx/ejemplos/posts/1?message=true
For apps script web apps embedded in classic google site,querystring parameters work well. Instead do not work if embedded in new google site,and this is a big problem, means that classic web sites that uses querystring cannot be migrated, and soon classic google site will stop working.
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.
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.