gapi.load versus gapi.client.load - javascript

In Google's JavaScript API's, what's the difference between gapi.load() and gapi.client.load()? How interchangeable are they and when should I use one versus the other? I see both are used in the Google Drive Realtime API sample code.

As indicated by the CORS documentation, the gapi.load function is used to dynamically load specific JavaScript libraries.
As documented in the description of the gapi.client.load function (which is provided by the "client" JS library), gapi.client.load is used to build a JavaScript interface for accessing specific HTTP(S) APIs; you can also do this sort of thing yourself using API discovery (search for it to find docs) and sending API requests directly with gapi.client.request or CORS.
Edit: added clarification based on Brian Slesinsky's follow-up comment and made minor wording changes.

After researching this, here's my simple take:
gapi.load() loads the JavaScript client library. That is to say, it's loading gapi. Without this gapi won't work.
gapi.client.load() is for loading an interface for one of the many Google APIs. The loaded API interface will then be in the form gapi.client.api.collection.method. For example, the Moderator API would create methods like gapi.client.moderator.series.list.
You most likley need both.

Related

How to customize a ppapi which could be used by Javascript?

I am researching on the Chromium PPAPI. After looking through all APIs from the official reference here: https://developer.chrome.com/native-client/cpp-api-dev, I seldom found any APIs that could be used by, or communicate with JS directly. In my opinion, a plugin process will set up a PP::instance and all functions within this instance would be loaded. Take video_capture.cc as an example, you could find it under /ppapi/examples/video_capture in chromium source codes. In this example, a customized PP::instance called VCDemoInstance registered some methods, yet I found only HandleMessage() could communicate with JS layer. From JS, you might use postMessage() to pass something to HandleMessage() above.
So here is my key question: Is there a way to create or define a method in PP::instance that could be used by or communicated with JS layer directly? Is it possible to register a JS object and call PPAPI like obj.apiFromPlugin? At lease I knew in Opera JSPP framework, it could be done.
Please correct me if anything is wrong. You're appreciated.
After digging into PPAPI, I couldn't find a way to create an JS object in plugin. I finally switched to Chromium Embed Framework which can port content API to JS. Using CefV8Handler may solve my question absolutely.

GAS: How to allow other people to use your library without sharing the code

How can I create a library in google app script in which I can share just the library key and people can use it, without sharing the code properly? I am trying hard to find a solution, but I failed.
I don't want to share the library for the world. I just want to use the library in different google drives, without having to share the code, but just the library/project key.
I found this link on stackoverflow that the guy had basically the same question as me, but it didn't has a good answer: How to share Spreadsheet with reference to a custom (private) library
Thanks in advance!
it is currently imposible with you requirement to end up "sharing a library key."
you must give at least read access to the library file for this case of running the script functions directly from the spreadsheet.
Once a script uses the library, and the user has view permission on the container script, a curious user could use the apps script debugger to "step into" a library function and there it is, the library source code.
If you were to instead publish the script as a web app, you could hide the library but that option does not apply in your case as you are making copies of the spreadsheet, and services do not get copied, need to be re-published.
Another option, but which does not give the library key in your requirement, is to publish an apps script service that uses the library and implements an API, which the other scripts (inside each spreadsheet copy) use. This however will not scale as quotas will be deducted from the API service publisher, and not the users that call the API.

From where am I supposed to install OpenSocial's gadgets.io?

I am trying to do this tutorial, http://developer.yahoo.com/yql/guide/yql-code-examples.html#yql_javascript
and it says to use gadgets.io, but does not say anything about installing it. Where do I get it from?
I should also say that I am trying to perform the query from a socket.io server.
gadgets.io is a javascript service exposed by the OpenSocial API which is available through OpenSocial containers. OpenSocial containers are used to host 3rd party web components known as gadgets and were originally contributed by Google.
There is no such thing as 'getting' the gadgets.io library, as it is exposed to gadgets running on a container. I'm not familiar with YQL, but I had a look at the link you provided and the code example they demonstrate is meant to be executed within some type of playground environment # Yahoo I guess - therefore their environment should support gadgets, i.e. an OpenSocial container.
Have a look at the original documentation of the gadgets.io.makeRequest in order to see similar examples. Hope it helps :)

Google Safebrowsing checking JavaScript

Is it possible to extract a website safebrowsing info by javascript? This can be with Google Safe Browsing API, is there any code, or any article?
Related to your comment: This is not a code repository. You'll need to do your own development.
Back to your question: I would like to warn you that you will be exposing your API key to the general public when using javascript (as it's a client-side technology). Furthermore, you're opening the door to abusers. In the end, your "secret" API key might get suspended by Google quicker than you think.
In short: it could be done using the GET request examples the API documentation provides, but if I were you, I would think twice if javascript is really the best option you have.

Generating JavaScript stubs from WSDL

I'm looking for a tool to generate a JavaScript stub from a WSDL.
Although I usually prefer to use REST services with JSON or XML, there are some tools I am currently integrating that works only using SOAP.
I already created a first version of the client in JavaScript but I'm parsing the SOAP envelope by hand and I doubt that my code can survive a service upgrade for example, seeing how complex the SOAP envelope specification is.
So is there any tool to automatically generate fully SOAP compliant stubs for JavaScript from the WSDL so I can be more confident on the future of my client code.
More: The web service I try to use is RPC encoded, not document literal.
Apache CXF has tools that generate JavaScript clients that talk soap.
Actually, any CXF service can have a javascript client autogenerated by doing a get to the URL with ?js appended. (just like ?wsld produces the wsdl) There are command line tools as well, but the dynamic generated stuff is kind of neat.
I had to do this myself in the past and I found this CodeProject article. I changed it up some, but it gave me a good foundation to implement everything I needed. One of the main features it already has is generating the SOAP client based off the WSDL. It also has built in caching of the WSDL for multiple calls.
This article also has a custom implementation of XmlHttpRequest for Ajax calls. This is the part that I didn't use. During that time, I think I was using Prototype javascript library and modified the code in this article to use it's Ajax functions instead. I just felt more comfortable using Prototype for the ajax calls, because it was widely used and had been tested on all the browsers.
It would probably be an overkill, but NetBeans has this feature.

Categories

Resources