To all Google Apps experts - please help me solve this. I'm rather stuck and I've not found any explanation yet on why this problem exists at all. I've included a live example to demonstrate the problem.
The problem may be view at this location ...
https://sites.google.com/a/growthhq.net/faulty-picker/
A Google Apps script made available in a Google Sites using the Apps Script gadget has stopped functioning recently. The crazy thing is that the app works perfectly using the 'dev' and 'exec' urls for the app directly, but when embedding the app in Sites (with the 'exec' url and Apps Script gadget), and the button is clicked, the form comes up blank.
I know that the UiApp is deprecated (sadly, this had some good attributes) but I don't want to change the rest of the code at this stage.
What can I do to get the Picker to show correctly in sites? Is the referrer inadequately specified? I'm at a total loss.
The activated referrers are:
*.google.com
*.googleusercontent.com
I have extracted (and simplified) the code portions for testing purposes. This working test code follows:
// refer to https://developers.google.com/apps-script/guides/dialogs#file-open_dialogs for setting up OAuth
function doGet()
{
var app = UiApp.createApplication();
var buttonHandler = app.createServerHandler('utilityPicker');
var button = app.createButton('Open Picker', buttonHandler)
app.add(button);
return app;
// This is a dummy to activate
DriveApp.getRootFolder();
}
function utilityPicker(e){
var app = UiApp.getActiveApplication();
var authToken = ScriptApp.getOAuthToken();
Logger.log(authToken);
var docPicker = app
.createDocsListDialog()
.setOAuthToken(authToken)
.setDialogTitle('Select a Google Spreadsheet or Form to be used by this Workspace')
.setMultiSelectEnabled(true)
.addView(UiApp.FileType.FOLDERS)
.showDocsPicker()
;
Logger.log(docPicker);
docPicker.addView(UiApp.FileType.SPREADSHEETS);
var handler = app.createServerHandler('pickerPrimarySpreadsheet');
docPicker.addSelectionHandler(handler);
return app;
}
function pickerPrimarySpreadsheet(e)
{
Logger.log(e.parameter);
}
Please help.
got the same problem,
found some google group forum where some people had to
add
.setOrigin('https://script.google.com')
to the pickerbuilder
still does not solve my problem, if u got a working solution to use on google sites please share
Related
I am trying to learn Apps Script and some fron-end web dev. I wrote some some code in Apps Script and I am trying to render it in a Google Site.
Here is the doGet function that I use in my Apps Script:
function doGet() {
var template = HtmlService.createTemplateFromFile('Index');
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
Interestingly, the script renders itself when I use the Google-given URL:
https://sites.google.com/corp/view/vrajlinkshortener
However, that is not the case when I enter the custom domain:
www.wharton.ml
I checked the documentation and I still could not figure out why a custom domain would prohibit Apps Script form working.
Any tips? Thanks!
You need to set the option XFrameOptionsMode to ALLOWALL.
XFrameOptionsMode
https://developers.google.com/apps-script/reference/html/x-frame-options-mode
Setting XFrameOptionsMode.ALLOWALL will let any site iframe the page, so the developer should implement their own protection against clickjacking.
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
As stated in the comments below (Shan Eapen Koshy said) check that your browser is logged into one Google account only.
Just add below, it is working
function doGet(e){
var temp = HtmlService.createTemplateFromFile('html')
return temp.evaluate().setTitle("Booking Window").setSandboxMode(HtmlService.SandboxMode.IFRAME).setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
}
I'm creating a simple child page in a Google site using Apps Script.
function createLibraryEntry(sessionObject){
var site = SitesApp.getSite("student.vis.ac.at", "professional-development-library");
var library = site.getChildByName('library');
var sessionPage = library.createWebPage(
"session1234",
"session1234",
"<h1>Session 1234</h1>"
);
}
Having read the documentation and done a fair amount of searching I'm unable to find a way to disable comments or attachments, on creation, for the new page. Neither can I find a way to set them on the page, by script, after creation (this can be achieved in the sites UI through 'page settings').
Can anyone help with this please?
I'm trying to add a feature to my website as follows:
Clicking a button appends text to a Google document.
Obviously I will need to create an Apps Script in the drive. The question is how to trigger the Apps Script from my website. You can assume that I am the owner of the drive/document and so have permissions to edit it in any way I like.
I have looked at these topics:
Workarounds : How to edit native google documents programatcally?item
How to programmatically manipulate native google doc files
It seems they are all actions performed from the drive itself and not triggered remotely.
I have also looked up the Apps Script API in Google but have not found a way to do this. Is it even possible?
Yes, it is possible.
First write an Apps script that changes your desired document. Then deploy it as a web-app running as you that anyone has access, even anonymous. Check out the guides at Apps Script page to see how to write your script as a web-app.
Your script will then have a public url, which you can call from your website and have it run "remotely" normally.
To provide an example of what Henrique suggests, here is a small webapp that adds text to a publicly viewable document I own (it doesn't need to be public except for anyone here to check it works !)
I wrote it using UiApp but you could of course use HTMLService if you prefer...
The app runs as me but is accessible to anyone even anonymous.
// publicly viewable test doc url : https://docs.google.com/document/d/1THzBTURxGr2CdUmcZ7i2zD-RM8I3im2JCSHI3BHlkeM/edit
function doGet(){
var app = UiApp.createApplication().setTitle('docEdit');
var panel = app.createAbsolutePanel().setSize('100%','100%').setStyleAttributes({'padding':'40px','backgroundColor':'lightBlue'});
var text = app.createTextArea().setName('text').setPixelSize(500,300);
var grid = app.createFlexTable().setId('grid');
grid.setText(0,0,'Add your text').setWidget(1,0,text);
var handler = app.createServerHandler('writeText').addCallbackElement(panel);
grid.setWidget(2,0,app.createButton('update document',handler).setId('btn'));
app.add(panel.add(grid));
return app;
}
function writeText(e){
var doc = DocumentApp.openById('1THzBTURxGr2CdUmcZ7i2zD-RM8I3im2JCSHI3BHlkeM');
var now = Utilities.formatDate(new Date(),Session.getScriptTimeZone(),'MMM/dd/yyyy # hh:mm:ss');
var body = doc.getBody();
body.appendParagraph('Append text on '+now+' : '+e.parameter.text);
doc.saveAndClose();
var app = UiApp.getActiveApplication();
var grid = app.getElementById('grid');
grid.setWidget(3,0,app.createHTML('Thanks,<br>Your text has been added to the document'));
app.getElementById('btn').setEnabled(false).setHTML('Button disabled');
return app;
}
In my Google Gadget JavaScript, I have an URL to call from Google Apps Script.
function getFileId(postData) {
var params = {};
var url = "https://script.google.com/a/macros/mycompany.com/s/AAABBBCCCDDEEE-FFF-GGG/exec";
params[gadgets.io.RequestParameters.POST_DATA] = postData;
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
gadgets.io.makeRequest(url , responseFileId, params);
};
So, when the function responseFileId() has returned obj.text, it actually goes to the mycompany.com login screen. That means it needs authentication from that Gadget I did. Didn't that Google Gadget hold my current domain's Google credential for running the Google Apps Script at "https://script.google.com/a/macros/mycompany.com/s/AAABBBCCCDDEEE-FFF-GGG/exec"?
I tried to run manually with Google Chrome browser, (https://script.google.com/a/macros/mycompany.com/s/AAABBBCCCDDEEE-FFF-GGG/exec) and it returns value without showing up the login screen...
Can someone tells what step has been missing for this? Has this something to do with Google OAuth?
Instead of doing this. I found a better idea => Using tags for remote website.
I'm trying to add a map image to a panel in Google Apps Script. Every time I load the UI, I am greeted with the following image:
This is the Google image for being over your quota. Well, I've never used the maps functionality before. I get the same result on two different domains/different accounts. There's no reason I should be over any limit.
Here's a simple script that's broke:
function main() {
var app = UiApp.createApplication();
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var panel = app.createVerticalPanel();
var map = Maps.newStaticMap()
.setCenter("1600 Pennsylvania Ave, Washington D.C.")
.setZoom(14);
var mapUrl = map.getMapUrl();
var image = app.createImage(mapUrl);
panel.add(image);
// add a label with the URL string
var labelUrl = app.createLabel(mapUrl);
app.add(labelUrl);
app.add(panel);
sheet.show(app);
}
And actually, while writing this example, I saw that it would work sometimes, and not others. I'm really confused.
In the example above, the URL is also written to a label on the UI. If I manually copy that and paste into my web browser, I have no issues viewing the map.
Anyone else experiencing this? Have some tips?
I'd suggest that you raise an issue on the Issue Tracker if you are 100% sure that you haven't hit the quota limits. (recollect if you have any other scripts left of triggers that can eat into your quota)
One possibility that I haven't seen anywhere else is that you might have your API Key locked down by IP. Frustratingly, Google gives you this same image whether you are over quota, or the IP is blocked.
In the Google Developers Console, check under API & Auth -> Credentials and click "Edit Allowed IP's". Be careful opening that up, as anyone can take your API Key and stick you with the usage.