Google Maps API密钥错误 [英] Google Maps API Key Error

查看:440
本文介绍了Google Maps API密钥错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图连接我的PHP脚本到谷歌地图API使用CURL它连接正常,但当我通过API密钥,它说它是无效的,下面是一些我使用的代码来获取统计...

I'm trying to connect my PHP script to the google maps API using CURL it connects fine but when i pass the API key it says that it is not valid, below is some of the code I'm using to get stats...

<?php
    $url = 'https://maps.google.com/maps/api/geocode/json?address={ADDRESS}&sensor=false&key={MY_KEY}';

    $cURL = curl_init();

    curl_setopt($cURL, CURLOPT_URL, $url);
    curl_setopt($cURL, CURLOPT_HTTPGET, true);
    curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
                                                'Content-Type: application/json',
                                                'Accept: application/json'
                                           ));
    curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);

    $result = curl_exec($cURL);

    curl_close($cURL);
?>

我已经尝试配置我的API密钥为两个服务器(由IP地址设置)和浏览器域名),请访问 https://code.google.com/apis/console/

I have tried configuring my API keys for both server (set by IP address) and browser (set by Domain Name) on the Google API page at https://code.google.com/apis/console/

我遇到的问题是每次发送请求时都会收到一条返回JSON消息:

The problem that I'm having is every time i send a request i get a return JSON message saying:

stdClass Object (
    [error_message] => This site or IP is not authorized to use this API key.
    [results] => Array (
    )
    [status] => REQUEST_DENIED
)

如果我尝试在有问题的计算机上的网络浏览器中转到url
https://maps.google.com/maps/api/geocode/json?address=The%20White%20House,%20Washington&sensor= false& key = {MY_KEY}我遇到同样的问题:

If i try to goto the url in a web browser on the computer in question https://maps.google.com/maps/api/geocode/json?address=The%20White%20House,%20Washington&sensor=false&key={MY_KEY} i get the same problem:

{
   "error_message" : "This site or IP is not authorized to use this API key.",
   "results" : [],
   "status" : "REQUEST_DENIED"
}

服务器类型:


  • O / S: Windows Server 2008 R2 x64

  • 服务器:UwAmp 2.2.1

  • PHP: 5.4.15

  • MySQL: 5.6.11

  • O/S: Windows Server 2008 R2 x64
  • Server: UwAmp 2.2.1
  • PHP: 5.4.15
  • MySQL: 5.6.11

感谢您提供任何帮助!

推荐答案

API密钥不是您使用谷歌地图API。这是一个令人困惑的错误消息,谷歌回复在这种情况下。只需从您的网址中删除& key = {MY_KEY}即可。

The API key is not required for your use of google map API. It is a confusing error message that google replies with in this case. Just remove from your URL the '&key={MY_KEY}', and you should be fine.

这篇关于Google Maps API密钥错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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