Reputation: 67
I am using PHP cURL to retrieve Google place information using my Google API key, but getting error whenever I put any http referrer. Any idea please?
{
"error_message" : "API keys with referer restrictions cannot be used with this API.",
"html_attributions" : [],
"status" : "REQUEST_DENIED"
}
My HTTP Referer
*mywebsite.local:8080*
*.mywebsite.local:8080*
*www.mywebsite.local:8080*
mywebsite.local:8080*
www.mywebsite.local:8080*
http://www.mywebsite.local:8080*
http://mywebsite.local:8080*
MY Code
$url = 'https://maps.googleapis.com/maps/api/place/details/json?placeid=" . $place_id . "&key=SECRET_KEY;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$json = curl_exec($ch);
curl_close($ch);
For information I can't use server referer, because my website using dynamic ip.
Any advice for me?
Upvotes: 3
Views: 4283
Reputation:
It look like you making the API call server side. Because you have placed a referrer restriction on your API key, it will be limited to executing on the browser with the web service APIs.
You can find the other web service APIs on this page: https://developers.google.com/maps/web-services/
If you are using any of the web service APIs with an API key that has referer restictions, your requests will fail with the error message: "API keys cannot have referer restrictions when used with this API." You should switch to using a server restriction.
You'll want to create a separate key to use server-side. You can change your restriction from a browser restriction to a server restriction by using IP addresses to restrict access, instead of browser referrers.
Check this APIs FAQ on switching key type to a server restricted key: https://developers.google.com/maps/faq#switch-key-type
Upvotes: 1