![](/img/trans.png)
[英]Getting a HTTP 403 Forbidden Error - Google Geocode API Request with PHP
[英]getting no response from php google geocode rest api request
我沒有得到任何回應,也沒有從此php代碼中得到任何錯誤。 請問有人知道我在做什么錯嗎? 看起來很簡單:
的PHP:
$details_url = "https://maps.googleapis.com/maps/api/geocode/json?address=436+Grant+Street+Pittsburgh&sensor=false&key=mykey";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$response = curl_exec($ch);
print_r($response);
您從不費心告訴curl有關您的網址。 你應該有
$ch = curl_init($details_url);
^^^^^^^^^^^^
要么
curl_setopt($ch, CURLOPT_URL, $details_url);
請注意,print_r不是一個好的調試工具。 您可能從curl_exec中得到了一個布爾假,而print_r根本不會顯示:
php > $x = false;
php > print_r($x);
php > var_dump($x);
bool(false)
更好的選擇是
$response = curl_exec($ch);
if ($response === false) {
die(curl_error($ch));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.