Addramyr
Addramyr

Reputation: 354

Google Maps API Key Error

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);
?>

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/

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
)

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"
}

Server type:

Thanks in advance for any help!

Upvotes: 1

Views: 4168

Answers (2)

user3867916
user3867916

Reputation: 1

You could create table location in your mysql.every time you send a request .insert it to databse. after that you can count request by using count record in your database.i used this solution

Upvotes: -1

Andrew - OpenGeoCode
Andrew - OpenGeoCode

Reputation: 2287

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.

Upvotes: 2

Related Questions