如何为Google地图抓取无效的API密钥 [英] How do I catch an invalid API key for google maps

查看:109
本文介绍了如何为Google地图抓取无效的API密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码:

 < script src =http://maps.google.com/maps? file = api& amp; v = 2& amp; amp; amp; amp;& amp; amp; amp; key = bababtype ='text / javascript'>< / script> 

如果键无效,它会弹出警告,但我想在此执行一些操作案件。我不知道如何去钩住它。任何想法? 解决方案

Google不提供检查Google Maps API密钥的外部方法。因此,你无法用例如该代码是否有效 abcde1234 并获得 TRUE / FALSE 响应。



有关如何生成Maps API密钥。但我建议你看看 Mike Williams介绍 GValidateKey 函数。这是实际进行魔法验证的功能 - 它的确切功能,比如从Google帐户/域创建哈希值 - 我们不知道。



我看到两个您检查提供的API密钥是否正确的问题的解决方案:


  1. 用一些自定义代码覆盖收到的警报(检查警报或检查是否在页面加载后以X秒的时间发生警报)
  2. 以某种方式获取 GValidateKey 函数以事先验证您的密钥。也许你可以在引用API Javascript之前调用它?对我来说听起来有些ha ... ......

您可能会遇到的问题是您不知道Google实际检查的内容。推荐人,引荐网站和主持人 - 很多可能性(服务器的IP地址不是,而是名称加上一些附加信息)。


I have this code:

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=babab" type='text/javascript'></script> 

If the key is invalid then it pops up an alert, but I want to perform some action in this case. I'm not sure how to hook into it though. Any ideas?

解决方案

Google does not offer an external method of checking the Google Maps API key. Hence you cannot query some service with e.g. "Is this code valid abcde1234" and get a TRUE/FALSE response.

There is a discussion on how the Maps API key is generated. But I suggest you look at a post from Mike Williams about the GValidateKey function. This is the function actually doing the magic validation - what it exactly does, like creating a hash from your Google account / domain - we don't know.

I see two solutions for your problem of checking whether the API key provided is correct:

  1. Overwrite the incoming alert with some custom code (check for the content of the alert, or check if an alert occurs withing X seconds after page load)
  2. Somehow get the GValidateKey function to validate your key beforehand. Maybe you can call it before referencing the API Javascript? Sounds kind of hackish to me...

The problem you will likely have is that you don't know what Google actually checks. The referrer, the referring site, the host - many possibilities (it is not the IP address of the server, but the name plus some additional information).

这篇关于如何为Google地图抓取无效的API密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆