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.
Related
I´ve created a spreadsheet with a script in it. I shared it with the url /copy and copied it to another account i own, just to test it. Then when i run the script it asks me authorizations. I approve them, the script runs and finish, but there are some sentences that don´t run beyond having authorized them. Some of those sentences are:
GmailApp.markMessageRead(mail[0]);
GmailApp.moveMessageToTrash(mail[0]);
sheet[2].sort(2);
sheet[2].sort(1);
sheet[2].deleteColumn(3);
The difference i see is that when i run the script for the first time in the original account pops up the "this app is not verify" window (i accept the request), but in the other account this pop up doesn´t show. Only the next authorization pops up.
The script takes an attachment from an email copies it in drive, converts it to spreadsheet and takes the glucose values for ordering them in the main sheet.
I can´t really find the solution and i´d like to share this spreadsheet because it could be useful for many diabetics. It works properly for me, but not when i share it.
This is the link: https://docs.google.com/spreadsheets/d/1ozIhv6DWD5O9uzn9z713HT1N0cFfncgwgKZ9FYxY0HQ/copy
I´m new at GAS and this is my first script. I´m a C programmer.
Thank you!
I paste the code below.
function myTidySgr() {
var sps = SpreadsheetApp.getActiveSpreadsheet()
var sheet = sps.getSheets();
var rowsprincipal = sheet[0].getDataRange();
var principal = rowsprincipal.getValues();
var busqueda = GmailApp.search("is:unread subject:(exportar.csv)
has:attachment", 0, 100);
var mail = busqueda[0].getMessages();
var MySgr = mail[0].getAttachments();
var blob = MySgr[0].copyBlob();
GmailApp.markMessageRead(mail[0]);
}
i found out what the problem is!
When i share the spreadsheet to a G Suite account it doesn´t work because i cannot authorize some permissions because i´m not the G Suite´s administrator. Apparently there are some security limitations.
I copied the spreadsheet to a common gmail account and it worked properly.
Thanks anyway!
Regards
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
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;
}
Is it possible to add an autocomplete in a google spreadsheet script with a remote source?
Below is one of my attempts to do so but I have no idea where to go from here (I am a newb to google scripts):
function my_autocomplete(){
var list = ['dog','doog'];
var app = UiApp.createApplication();
var suggestBox = SuggestBoxCreator.createSuggestBox(app,'autocompleter',200,list);
app.add(suggestBox);
var doc = SpreadsheetApp.getActive();
doc.show(app);
}
I've googled my heart out but can't find a single example of an autocomplete with a remote source that is compatible with Google Scripts...is it even possible?
(I don't have to use/modify the autocomplete example I have above, so if there's another approach I'm all ears! thx!)
Google suggestboxcreator and you will find this https://sites.google.com/site/scriptsexamples/learn-by-example/uiapp-examples-code-snippets/suggest-box. Use that library, thou it does the search server side. Make one with htmservice and do it client side so its faster. Write the selected value into the active cell of the active spreadsheet.
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.