Determine where a gmail add-on is running - google-apps-script

I'm developing an add-on for gmail and I'd like it to show different texts depending on whether it's running on the browser or on the android app, but I don't know if it's possible.
I've tried using HtmlService.getUserAgent() and the deprecated UiApp.getUserAgent(), but both of them return null; and I haven't found any other possibilities on the documentation.
Can anyone help on this? Thanks!

Solved. The function provided as onTriggerFunction of the appsscript.json file has an event parameter with a clientPlatform property that can be either 'web' or 'android'.

Related

Google Apps Script function is not getting executed after authorization

I'm working on one existing apps script(sheets) app, when user clicks on Save button for the first time it is asking for the authorization which is the expected functionality. But the problem is after authorization the save function is not getting invoked, I need to click it again. So some users are getting confused with this behavior since they are thinking that the data got saved after authorization.
My questions are
Is this the default behavior?
If it is default, how to overcome this case?
Is there any way to execute the function automatically after authorization?
I couldn't paste the code here due to some confidential issues, looking for any links or solutions.
Thanks in advance.
The behavior you report actually seems to be a bug.
It has already been reported on Google's Public Issue Tracker and seems to being worked on.
Unfortunately I cannot think of another workaround than informing your users about the current situation.
I can only recommend you "star" the issue to increase the visibility for its importance and get updates about its fixing status.
For years this worked correctly for me, scripts were executed after authorization. Only since today it does not work anymore with any of my scripts. Apparently this has been fixed at some point and now we have it again ...

Azure APIM Fails to Create API from Function App

When I try to create an API in APIM by using Create from Function App, I fill out the fields and click Create. The operation provides the wait dots and comes back in five seconds and says
Could not create an API. Please try again later.
I can create a blank API...but not one from an existing Function App. I have tried multiple combinations, No products, all products, no version, version..etc. No luck.
Thoughts?
Notes
The function in question is an HTTP Trigger.
The function works locally on my development box and in Azure.
APIM Tier is Developer
On that Function app, during Publish in Visual Studio I have reported that attempting to manage application settings before a publish fails and in trying to add a new one causes Visual Studio to unexpectedly close. Manage Application Settings on Publish Related, don't know.
Just a Ctrl + F5 solved the problem for me. Try it! ;)
I just ran into the same issue because I used Linux (Preview) instead of Windows. When I blew away the Function App and recreated a new one with Windows, my API Manager was able to create an API off it.
I have reproduce the same scenario. It is working for me. May I know, below details,
01.Hope you have tested your function and it is working fine.
02.What is the type of the function ? Hope that is "Http trigger" ?
03.What is you APIM tier ? (eg : development, basic etc.)
At this time the solution for me was to use Microsoft Edge instead of Chrome.
It seems Microsoft Azure portal is not working properly in Chrome and I noticed issues in several places. Parts of pages are not rendered at all and sometimes even errors like this pop up just because of the browser.
I had this same problem.
The fix was both simple and unexpected.
When importing the function app, simply enter "/" in the API URL Suffix field.
For me this changed the BaseURL field value. Originally it was just the host, ie http://hostname/. It then appended the endpoint the hostname, http://hostname/endpoint
This is done on the "Create Function from App" modal.
I had the same problem when trying to publish my Azure Functions application with several HTTP triggered functions through API Management running on Consumption plan. The plan did not have anything to do with the problem though.
What I did not realize was that my function app was not working properly when browsing it from the Azure portal. I had some configuration errors that prevented the app to work properly. When I resolved those, I succeeded to publish the application through APIM.
So, check that your application is working properly by browsing to it if you run into the problem described in this thread.
I had temporarily suspended (or stopped) my Function App. Restarting it resolved the problem.
I hope Azure could improve the error message, at least from UX perspective.
The issue was that the function did not actually work.
The Browse button that redirects to the page with the light bulb and the text Your function app version X is up and running did show, but the function still didn't work.
The function error had to be fixed before when importing to the APIM was done.

Google Apps Script editor not launching

From this morning I have no possibility to edit scripts. My existing script link to a spreadsheet continue to work but when I try to edit them or to edit a new one , I only get a shaded upper bar, and no possibility to use it.
Last times one of my scripts was getting some errors, is it possible that google "ban" me from using script due to too much memory using?
Thanks in advance,
david
I used Chrome Incognito mode as a temporary fix.
Hopefully, this works for you as well.
Switch you drive locale settings to English and it will work. This is a temporary workaround to use until they fix the bug. see issue 4339
Turned out I was still signed into another account despite the UI suggesting otherwise. Restarting the browser and checking who you are logged in as in Drive (and potentially signing the incorrect user out) fixed the problem for me.
Exactly. I was signed with different account without permits. Request access to the Sheet with full access without restrictions and it will work :)

How to close a browser window from Google Apps Script?

I have a Google Apps Script for Google spreadsheets which opens a secondary browser window (for authentication to an external system).
After the authentication we get a redirect to the webapp part of the script (doGet).
How do I close the browser window from Google Apps Script (so that the user can continue in the spreadsheet)?
Have you developed your interface using UiApp or HtmlService?
If it's HtmlService, have you tried google.script.host.close()? I'm not sure if it's going to work though. If you test it, please give feedback here. -- edit from feedback on comments, it seems that does not work for standalone scripts, just if it's embeeded on sidebars or dialogs.
If it's UiApp, then it's not possible, see issue 474.
I changed the design to solve the issue:
1) I do no longer use a webapp in GAS to wait for some authentications codes. We instead poll (via UrlFetch) our server from the GAS side until the authentication has completed.
2) I now let the authentication window close itself
window.open("","_self","").close();
The code might look tricky, but it works with current browsers. ( The more natural looking window.close() doesn't).

Google Drive “Share” dialog not showing for "writer"

We've incorporated Google Drive “Share” dialog into our web application which creates its own files, and it works perfectly thanks to the answer to another question, but only for document owner.
Even though "writers" can easily share documents from Google Drive, that seems to be not possible externally, i.e. in our app.
This is the code which works for "owners" but fails for "writers":
var s = new gapi.drive.share.ShareClient(appId);
s.setItemIds(fileId);
s.showSettingsDialog();
Curiously, the error in JS console is the same as one can see when the script is launched from a wrong URL:
Refused to display 'https://drive.google.com/share?id=0B....' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'
We haven't found anything related to possibility to share docs by various user roles in the documentation, so we wonder if that's a bug or undocumented restriction. Any ideas are welcome.
UPDATE
The issue seems to have gone - it looks like Google have changed something their end.
Your app should be checking the value of the writersCanShare attribute. If it's false, only owners can modify the file ACLs.