在 Google Jsapi 调用中是否必须使用开发人员密钥?
我一直像这样使用 Google Jsapi:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.3");
</script>
但是 Google 文档 建议这样做:
<script type="text/javascript" src="http://www.google.com/jsapi?key=YOUR_KEY_HERE"></script>
<script type="text/javascript">
google.load("jquery", "1.3");
</script>
根据我的经验,无论您是否包含密钥,它似乎都有效。
如果不使用密钥会遇到任何问题吗?
I've been using Google Jsapi like so:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.3");
</script>
But the Google docs recommend doing this:
<script type="text/javascript" src="http://www.google.com/jsapi?key=YOUR_KEY_HERE"></script>
<script type="text/javascript">
google.load("jquery", "1.3");
</script>
In my experience, it seems to work whether you include the key or not.
Will I encounter any problems if I don't use a key?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为您不需要它来加载 jQuery 等库,但同一个加载器可用于其他几个 API,例如 Google 地图,这可能需要有效的 API 密钥。
另外,这是谷歌关于使用密钥的说法:
I don't think you need it for loading libraries such as jQuery, but the same loader is used for several other APIs such as Google Maps, which may require a valid API key.
Also, this is what Google has to say about using a key:
截至今天(2012 年 2 月),开发指南中甚至不再提及 API 密钥:
http://code.google.com/apis/libraries/devguide.html
还有:
这意味着甚至不需要加载 google jsapi,但您可以简单地:
但是,使用
google.load
你可以:尽管我认为这是一个危险的功能,因为任何库的升级都必须在上线之前进行测试。
示例:
总结一下:在这两种情况下都不再需要 API 密钥,直接加载库的脚本标记更快、更简单,也是 Google 推荐的。
As of today (February 2012), the API key is not even longer mentioned in the dev guide:
http://code.google.com/apis/libraries/devguide.html
And also:
That means that it's not even necessary to load google jsapi, but you can simply:
However, with
google.load
you can:Although I'd argue, that is a dangerous feature, since an upgrade of any library has to be tested before going live.
Example:
To sum up: in both cases an API key is not needed any more, the script tag to load a library directly is faster, simpler and also recommended by Google.
自 2012 年 5 月起,Google Loader 不再需要密钥:
https://developers.google.com/loader/注册
另请注意,Google Libraries API 之间存在区别
以及 Google 加载程序。
As of May 2012, the Google Loader no longer requires keys:
https://developers.google.com/loader/signup
Please also note that there is a distinction between the Google Libraries API
and the Google Loader.
我想说的是,如果文档说您需要包含它,那么您应该包含它。他们可能会在没有进一步通知的情况下开始执行该规则,并且您的应用程序可能会停止工作。
如果您限制自己遵循公共 API,那么您应该可以避免 Google 更改其服务以及您的应用程序崩溃。
该建议也适用于任何其他非公共 API。
I would say that if the documentation says you need to include it, then you should include it. They may start enforcing that rule with no further notice, and your application may stop working.
If you restrict yourself to following the public API, you should be safe from Google changing their service, and your application breaking.
That advice holds for any other non-public APIs as well.
要求您包含密钥的原因是 Google 可以更轻松地跟踪其 API 的使用情况 - 因此,如果您有一个非常受欢迎的应用程序,Google 会注意到并可能会修改 API,以便它将来能够更好地工作。
我个人从不使用它们,因为它们让我的代码看起来很丑。
the reason for asking you to include a key is so Google can more easily track usage of their API - so if you have a very popular app, google will notice and possibly do work to modify the API such that it will work better in the future.
personally I never use them because they make my code look ugly.