Error checking on gapi.client.load - google-drive-api

I am writing javascript code to access Google Drive. The code examples show calls like:
gapi.client.load('drive','v2',callbackfunction);
How do I check to see that this call was successful?
I have tried:
result = gapi.client.load('drive','v2',callbackfunction);
But result is undefined.

There is no result to be returned from that call. It's simply loading a library. When the library has finished loading the callback will be called.

Related

Google Apps Script order of execution: why do functions get invoked merely by being defined?

In Javascript, the following code will execute only once, but in Google Apps Script it executes twice (obviously the body and script tags would be omitted):
<body>
<script>
hi();
function hi() {
alert('hi')
}
</script>
</body>
In other words, in GoogleApps script merely defining a function invokes it. The following in Code.gs executes with undefined arguments passed to it.
function createQuery(keywords, dateRange) {
}
How can I define functions without them being called? Pointers to the docs would be helpful. I have scoured them without success.
In GAS, you save and test functions using the toolbar at the top. By virtue of telling the function to run using the toolbar, you are calling the function. Any triggers that you have will also call it to run without 'calling' inside the code.
You can more minutely determine how and when a function runs by calling it later in the code. This can be done in nested functions or inside of other functions. Regardless of where you are defining the function, eventually you will have to either create a trigger or use the toolbar to run the function.
I'm not sure how you are experiencing a double call seeing as your reference code is not very in-depth. Keep in mind that to execute the script at all, you would have had to either set a trigger or run it yourself in which you are adding in an execution. If you execute code that tells itself to execute that same code, you would incur an infinite loop.
Users will be able to more accurately understand your question and issue and thus answer them should you provide more data and references. You may also want to read the references and guides on the basics of GAS and its use of Javascript.

Achieve Do after and before using ES6 Proxy

I've a View and Utility classes and wanted to hook-in the Utility method once View's job is done. So wanted to call the utility method (to add behavior to the view) once View's render call is done.
Using ES6 Proxy API, Is there a way to execute a method before / after executing the main method ? (aka method interceptions)
Similar to YUI3 Do API.
http://yuilibrary.com/yui/docs/api/classes/Do.html
Yes there is a way. Actually I'm trying to build the same thing and as long as you use a synchronous context I already got it working. Have a look at the code examples in the issue I created for my problem: stack overflow when returning an ES6 proxy through a promise
What you need to do to intercept the call is to use the ES6 proxy to get notified of the get-call that takes place to retrieve the function before the method is actually called.
In my example you can see that you get all the information about the call like what method was called with which parameters and also who called it and on which target it was originally called.

Why am I getting Unauthorized Message when calling MongoDb Function in Shell (Robomongo)

I have a simple MongoDb hosted in AppHarbor.com. I successfully connected to it using Robomongo and created a simple collection called 'User' and a function called 'insertUser' using Robomongo. But when I try to call the function in shell I get an "Unauthorized" message. I'm using the free Mongo db account in AppHarbor. Please tell me how to successfully call this function?
So it seems I need to issue the call in the following manner for it to work. Eval doesn't seem to work for some reason though.
db.loadServerScripts("system.js");
insertUser('aaa', 'bbb');
Robomongo is already creating function name. You need only a call.
For you - calling;
insertUser('aaa', 'bbb');
function;
db.User.insert({"UserName":param1,"Password":param2})

Can anyone explain the User Objects example in GAS documentation of HTML service?

I've been looking at this "example" in the GAS documentation, but there is no explanation accompanying it from the googlers documenting it:
https://developers.google.com/apps-script/guides/html-service-communication#user_objects
My question pertains to the successhandler and the passing of parameters to the updateButton function. When called in the onclick, the successhandler doesn't include the variables (within the parentheses) in it's call to updateButton. Following the successhandler call is the user object and getEmail but they seem to be out of order (the function updateButton has email before button).
So, how/why does this code work? I've tested it, and even rearranged the variables and what not but the only way it works is in the documentation's writeup. I am unable to understand how the updateButton function knows the parameter values when they are not included in the call to updateButton and they seem to be out of order in the example. Thoughts?
If I understood your question the return of the getEmail function at your GAS script will be redirect to your sucess Handler. You can try to use Logger.log(Session.getActiveUser().getEmail()) and check the return . The parameters order are first the values returned by the gas function and finally the element which triggered the action.

Pass function as an argument in a function javascript to NPAPI

On javascript Object i am invoking
obj.requestFileSystem(LOCAL,5*1024*1024) . This method is implemented in PlainNAPI Plugin , now i have to pass one success callback to this function as follows......
obj.requestFileSystem(LOCAL,5*1024*1024,initFS); // initFS is a function in javascript that is an argument to the success callback .
In NPAPI it is an object when the requestFileSystem is completed then initFS function in javascript should be called. How to return from NPAPI plugin to javascript and to execute initFS function.
function initFS(fs) {
alert('Inside the initFS');
alert(fs.root.getFullPath);
}
Please don't tell me what you're actually doing with this plugin, since it sounds like it's something akin to giving people access to things from a web browser that could easily be abused by someone else.
Basically a function is just an NPObject when it gets to your function inside NPRuntime; to call the function you just do a NPN_InvokeDefault on that NPObject.
Note that you must be on the main thread in order to call nearly all NPN_ functions.
EDIT: So if you have to do the callback from a different thread then your easiest solution is to use NPN_PluginThreadAsyncCall; basically you create an object to hold the data you need and call PluginThreadAsyncCall with that pointer as the void* parameter and it will get passed to the function you specify.
Make sure that A) the pointer will still be valid, and B) your function is able to free that memory after it runs. From the callback function you can call NPN_InvokeDefault safely.
Not that NPN_PluginThreadAsyncCall doesn't seem to work on Safari 5.1 anymore. If you need that support or if what I've explained doesn't make sense you might want to consider using FireBreath to build your plugin; it does all of this for you.