-->

gapi.client.load versus google.load

2019-04-05 16:07发布

问题:

I am confused about how to properly load Google's APIs. I see mentioned two different approaches:

First: Google API loader (https://developers.google.com/loader). I see this used like so within the html document:

<script src="https://www.google.com/jsapi"></script>

Then later in a JS file it gets used like this:

google.load('visualization', '1.0', {'packages':['corechart']})

Second: Google API Javascript Client (http://code.google.com/p/google-api-javascript-client/). This one gets loaded like:

<script src="https://apis.google.com/js/client.js"></script>

and then used later like:

gapi.client.load('fusiontables', 'v1')

If you look up the documentation for each of these two APIs I get the impression that the second approach is the current 'modern' approach, while the first is older. The older method supports fewer APIs that the newer one, but they are not the same. I am wanting to use both Fusion Tables and Google Charts in my application. As far as I can tell I think I need to load up both APIs.

My Questions: Are these two APIs indeed distinct and independent from each other? Am I correct in interpreting the "google.load" methods as being older "legacy" stuff? If I need to use both APIs, are there any conflicts between them?

Thanks for any ideas!

回答1:

Your assessment is correct. These APIs are distinct from each other, and there should not be a conflict in loading both of them (Although you should verify that both of their "on load" methods have been fired before doing any work). However I wouldn't characterize the google.load APIs as "legacy"; google.load is a general mechanism for loading certain Google JS clients, and is not a reflection of the status of the underlying client library.