在 Google Jsapi 调用中是否必须使用开发人员密钥?

发布于 2024-09-29 01:39:02 字数 629 浏览 4 评论 0原文

我一直像这样使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

聊慰 2024-10-06 01:39:02

我认为您不需要它来加载 jQuery 等库,但同一个加载器可用于其他几个 API,例如 Google 地图,这可能需要有效的 API 密钥。

另外,这是谷歌关于使用密钥的说法:

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:

The API key costs nothing, and allows us to contact you directly if we detect an issue with your site.

梦旅人picnic 2024-10-06 01:39:02

截至今天(2012 年 2 月),开发指南中甚至不再提及 API 密钥:

http://code.google.com/apis/libraries/devguide.html

还有:

首选方法是通过标准加载库
标签(如 ,
这将导致最快的加载。

这意味着甚至不需要加载 google jsapi,但您可以简单地:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

但是,使用 google.load你可以

始终加载最新稳定版本的API,请求版本
编号而不指定修订版本。所以,使用上面的例子,
请求版本 2 加载 API 的最新稳定版本,
例如,2.2.3。

尽管我认为这是一个危险的功能,因为任何库的升级都必须在上线之前进行测试。

如果您选择使用google.load加载库,则还需要设置google.setOnLoadCallback。

示例:

google.setOnLoadCallback(function() {
    google.load("jquery", "1.7");
});

总结一下:在这两种情况下都不再需要 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:

The preferred method is to load the libraries via standard
tags (as in ,
which will result in the fastest loads.

That means that it's not even necessary to load google jsapi, but you can simply:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

However, with google.load you can:

always load the latest stable version of the API, request the version
number without specifying a revision. So, using the above example,
requesting version 2 loads the latest stable revision of the API,
e.g., 2.2.3.

Although I'd argue, that is a dangerous feature, since an upgrade of any library has to be tested before going live.

If you choose to load libraries with google.load, you also need to set google.setOnLoadCallback.

Example:

google.setOnLoadCallback(function() {
    google.load("jquery", "1.7");
});

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.

审判长 2024-10-06 01:39:02

自 2012 年 5 月起,Google Loader 不再需要密钥:

https://developers.google.com/loader/注册

另请注意,Google Libraries API 之间存在区别

Google Libraries API 是最流行的开源 JavaScript 库的内容分发网络。

以及 Google 加载程序

Google API 加载程序可让您轻松导入一个或多个 [Google] API,并指定适合您需求的其他设置(例如语言、位置、API 版本等)。

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

The Google Libraries API is a content distribution network for the most popular, open-source JavaScript libraries.

and the Google Loader.

Google API loader allows you to easily import one or more [Google] APIs, and specify additional settings (such as language, location, API version, etc.) applicable to your needs.

戏剧牡丹亭 2024-10-06 01:39:02

我想说的是,如果文档说您需要包含它,那么您应该包含它。他们可能会在没有进一步通知的情况下开始执行该规则,并且您的应用程序可能会停止工作。

如果您限制自己遵循公共 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.

空宴 2024-10-06 01:39:02

要求您包含密钥的原因是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文