gapi.client.load versus google.load

半世苍凉 提交于 2019-12-05 17:36:22

问题


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.



来源:https://stackoverflow.com/questions/14113257/gapi-client-load-versus-google-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!