HTML Service: Communicate with Server Functions, cant call - google-apps-script

I follow the instruction here but it not work for me.
https://developers.google.com/apps-script/guides/html/communication
in Script Editor I was crate 2 file Code.gs and Index.html same as above link said. then I publish as web app. go to web app url and it show "hello world" -> it work for the Index.html but when back to Script Editor and chose View->log nothing here. Just "logging out" string show here. I guess that mean it fail to call server-side function. I still don't know how get it work.

If you published a 'Hello World' HTML page and then subsequently changed the version, you'll need to ensure that you're using the latest version of your code: developers.google.com/apps-script/guide_versions

Related

Create a web browser link that opens a file in Intellij. Possible?

Example, qbittorent can be made to open links that are of torrent files.
Email clients mailto:
Is it possible to create links in a browser that will open the given file in Intellij? (Not full path, but entire package possibly ).
Idea is that this will be created for bitbucket.
There is an open feature request to add idea:// protocol handler.
At the moment it works on macOS only out of the box. For other platforms you can try the third-party solution or other workarounds from the ticket comments.
There is also a built-in web server providing the REST API to open files.
It will work with the relative paths only when the IDE is already running and the project is open: http://localhost:63342/api/file/relative/to/module/root/path/to/file.kt.
With the JetBrains Toolbox App installed one will be able to use jetbrains:// protocol for navigation, it's work in progress and should be available in 2019.2.
See JBProtocolNavigateCommand.kt for the reference:
// handles URLs of the following types:
// jetbrains://idea/navigate/reference?project=IDEA
// [&reference[X]=com.intellij.navigation.JBProtocolNavigateCommand[.perform][#perform]]+
// [&path[X]=com/intellij/openapi/project/impl/JBProtocolNavigateCommand.kt[:23[:1]]]+
// [&selection[X]=25:5-26:6]+
Sample URL:
jetbrains://idea/navigate/reference?project=IDEA&fqn=com.intellij.openapi.application.JetBrainsProtocolHandler#getParameters
Toolbox URL matches regexp:
"${JetBrainsProtocolHandler.PROTOCOL}([\\w\\-]+)/navigate/reference\\?project=(?<project>[\\w]+)(&fqn[\\d]*=(?<fqn>[\\w.\\-#]+))*(&path[\\d]*=(?<path>[\\w-_/\\\\.]+)(:(?<location1>[\\d]+))?(:(?<location2>[\\d]+))?)*(&selection[\\d]*=(?<line1>[\\d]+):(?<column1>[\\d]+)-(?<line2>[\\d]+):(?<column2>[\\d]+))*"
There will be also UI for copying TBX protocol URLs directly from the editor similar to the Copy Reference action in the context menu. The same will work for IDE settings navigation.
As an update to #CrazyCoder's answer
This works* on Mac currently. (unable to test on anything else personally)
* There are some issues:
There is no context menu option for generating this link from clicking on a line of code
The keybinding (see below) generates the incorrect path, and it needs to be modified manually by either changing the sources root temporarily, or typing the missing path parts by hand.
There is a keybinding you can use to generate the url, under Preferences > Keymap > Copy Path/Reference > Toolbox URL. Note that the cursor location when using the keybinding matters. From what I can tell, if the cursor is at the beginning or end of a line, it generates a url with &path=..., else it generates with &fqn=.... The fqn option will often link to the wrong area of the code, especially when interfaces, libraries, auto-wiring, or anything not a direct vanilla class/object/function is attempted to link to.
I have filed an issue with more details on the broken path generated by the keybinding: https://youtrack.jetbrains.com/issue/IDEA-290640

Can't get Hello world example to work as a web-app

I am a total newbie to google-apps-script, but I can't believe the problem I'm having. I can't even get the Hello World! example to work as a web-app.
I have copied and pasted code from google's documentation website, and I still can't get it to work. (I tried more complicated stuff first, but then I started trying simpler and simpler code until I bottomed out with the below problem.)
When I publish the following code as a web-app:
function doGet() {
return ContentService.createTextOutput('Hello, world!');
}
Instead of seeing "Hello, world!" in the browser, I get the following error message:
The script completed but did not return anything.
I'm really at a loss here. I don't know how to try anything simpler, and again, the code snippet above was copied and pasted directly from the Content Service documentation page (https://developers.google.com/apps-script/reference/content/).
Any help with this problem is greatly appreciated.
Thanks in advance.
Thanks for the response Alan.
I created a new project and pasted the Hello world code into it, and it worked. I'll just work from this new project going forward.
...
Now that I have a few more minutes of experience, I think my problem was with version control. I thought that when I made a change in my code and updated the current version, then the current version published as a web app would reflect this change in my code. However, it seems that you have to create a new version of your code in order for your newly-published web-app to reflect the most recent changes in your code. My problem was that I was not creating new versions as I changed my code, so I kept accessing the old code which was always the same as when that version was first created.
(Using the Test web app for your latest code link (located in the Deploy as web app dialog which is accessed from the Publish menu) did reflect my most recent changes, but this was not adequate for my testing purposes since I was sending arguments to my web app url. (The latest code link only calls your web app with a read-only version of your web app url that has no arguments appended to it.) In order to properly test the web app with all arguments appended to the url, I needed to re-publish the new code under a different version number in order for those changes to be reflected in the web app that was published. Only then I could access this url that pointed to my latest code with all of my arguments appended.)
Again, just hitting the Update button in the Deploy as Web App dialog without specifying a new version does not actually update the current version with your new code. In order for your latest/newest code to be deployed you have to create a new version of your code that will reflect your latest changes. In order to create a new version, you first have to choose Manage versions... from the File menu and then save a new version that reflects your most recent code changes by hitting the Save New Version button. Once you have done this, you can choose to publish this new version in the Deploy as Web App dialog. The url for your web app will then access whichever version of your code that you last deployed/published.
I know that everyone on here probably already knows this, but I thought I'd clarify what my problem was (problem understanding the work-flow of the code-publish cycle) in case any newbie in the future also runs into this problem.
<<<<<UPDATE>>>>>
See the answer from Serge below about how to use the dev version of your web app url with parameters appended to it. In many cases, this can alleviate the need to create new (exec) versions of your web app as I described above if/when you are making only incremental changes to your code.
In order to get hold of your dev url in the browser address bar so you can copy it for further use (instead of getting the script.googleusercontent.com... url that is used to temporarily serve the content/output of your web app) just call an undefined function in your web app code. Then use the Test web app for your latest code link to call the dev version of your web app. This will cause an error page to be returned, and your dev url will then be available for copying in the browser address bar.
Following these steps I was able to get the Hello World Script to run:
Go to script.google.com
Paste your above code into the script area.
Save as Hello World.
Publish as version 1.0.
Go to the url it generates and "Hello, world!" is now displayed.
You can now also test the web app with the latest code when publishing.
Your statement that the .dev url is not able to support parameters is not exactly true (The latest code link only calls your web app with a read-only version of your web app url that has no arguments appended to it). Actually it does just like the exec one but you can only call this url directly from the browser (and not from another app) because only you can access the app using this special url.
demo code :
function doGet(e) {
var valToReturn = ContentService.createTextOutput('the parameter was '+e.parameter.val).setMimeType(ContentService.MimeType.TEXT);
return valToReturn;
}
The test .dev url with parameters goes like this :
https://script.google.com/macros/s/AKfycb___vWxs/dev?val='test'
and the return you get in your Browser is :

do I need to save a new version every time I edit app script code for a UI?

following the tutorial for google app script - Building user interfaces HTMLservice section
all is well with the initial simple hello world demo - one jave script file and one HTML file.
if I edit the HTML body to,say foo bar and the use the menu item Publish - then update - the resultant web page has not changed.
if I save a new version after that minor edit and publish the new version, then sure, the new HTML is displayed.
but surely I don't have to save a new version after every edit...
are there any clues as to why "update" (without a version change) might not work - cacheing?
with many thanks
Chris
Okay so answering my own question.
The Deploy as web app dialog contains a text field with the latest URL, but a small piece of text below that says
Test web app for your latest code
latest code is a link which when pressed outputs the latest SAVE.
The URL in the text field is the latest VERSION.
Perhaps this could be part of the deploying tutorial at
https://developers.google.com/apps-script/execution_web_apps
Problem solved!

Run a program from a local webpage

I'm trying to use a webpage as an entry point for a kiosk. The HTML will be run in local, I need two things:
<a href="c:\Users\Admin\Documents">...
Which works like a charm
And..
<a href="c:\Program Files\Windows Live\Mail\wlmail.exe">...
(program just an example, all programs are the same)
Which works but.. it prompts to download the file then you are prompted to start it.. Is there any way to do this directly, like click and bam you opened notepad.exe? Maybe using a Java applet?
EDIT:
I know it can't be done remotely, I'm talking about local files.
The file will be accessed as c:\myhtml.html
And will open ONLY already installed files, nothing from the web.
If i get your question right , the closest thing to get what you want would be using *.hta which is a HTML Application that runs outside the browser window just like a normal app.
<script type="text/javascript" language="javascript">
function RunFile() {
WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("c:/windows/system32/notepad.exe", 1, false);
}
</script>
Bit more info here:
http://www.kunal-chowdhury.com/2010/09/how-to-execute-local-file-using-html.html
The right way to implement this is by creating custom protocol in Windows. Details in the MSDN article "Registering an Application to a URI Scheme"
No, this is security issue, browsers don't allow it because it could be security risk to run apps without prompt, just by clicking on the link.
There are several technologies like java WebStart and ASP ClickOnce - they will install the app more or less automatically, signing the application helps too - the messages the user gets look less scary.
Correct me if I didn't understand you. If you're running the web page locally (http:\127.0.0.1) and want to execute a program in the same machine, it will depend on the technology that you're using, for example in php you could use exec() to execute a program on user input but it will run on the server side.

Change the playing video

I'm trying the following code http://code.google.com/apis/ajax/playground/#change_the_playing_video
It works well when runned from the playground page. But if I create a new localfile with the source code provided as sample I get the following error:
ytplayer is not defined
at line 40:
if(ytplayer) {
ytplayer.loadVideoById(videoID);
}
It looks like for some reason I don't get access to some part of the javascript needed by the sample.
Is it just me? Or sample code don't run outside the playground page?
Pretty sure it's a security problem with flash. When I try to load it locally, I get the following popup, but it works fine on my server.
(source: fullahead.org)
If you check out the Developers section in the following Adobe reference, you should be able to get it working.
This has to do with same-domain restrictions in Flash. Local files trying to access resources on the internet counts as "cross-domain" access. To whitelist your local file, add it's location to the global security settings. Click on "Edit locations..." and then "Add location...".