ZERO_RESULTS from Google Search API“ findplacefromtext”

问题描述 投票:1回答:1

使用Google Place API“ findplacefromtext”时出现怪异行为。 https://maps.googleapis.com/maps/api/place/findplacefromtext/json

[当通过浏览器使用API​​来检查响应时。显示有效响应。屏幕截图已附上。 enter image description here

当在PHP中通过CURL on Linux TerminalCURL in PHPfile_get_contents使用API​​时,响应为:

{
   "candidates" : [],
   "status" : "ZERO_RESULTS"
}

这里是Google API。出于安全原因,未共享“ API KEY”:https://maps.googleapis.com/maps/api/place/findplacefromtext/json?key=APIKEY&inputtype=textquery&fields=photos,formatted_address,name,rating,opening_hours,geometry,reference,place_id&input=Lollapalooza+Argentina+Mart%C3%ADnez+Argentina

API密钥是有效的,并且得到了适当的授权。

更改响应的原因可能是什么?

php curl google-api google-places-api file-get-contents
1个回答
1
投票

对我来说很好。

$url = "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?key=APIKEY&inputtype=textquery&fields=photos,formatted_address,name,rating,opening_hours,geometry,reference,place_id&input=Lollapalooza+Argentina+Mart%C3%ADnez+Argentina";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

$response = curl_exec($ch);

curl_close($ch);

print '<pre>';
print $response;
print '</pre>';

哪些印刷品:

{
   "candidates" : [
      {
         "formatted_address" : "Martínez, Buenos Aires Province, Argentina",
         "geometry" : {
            "location" : {
               "lat" : -34.4811677,
               "lng" : -58.5165812
            },
            "viewport" : {
               "northeast" : {
                  "lat" : -34.47967187010728,
                  "lng" : -58.5156313
               },
               "southwest" : {
                  "lat" : -34.48237152989272,
                  "lng" : -58.51943089999999
               }
            }
         },
         "name" : "Lollapalooza Argentina",
         "photos" : [
            {
               "height" : 1536,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/115749286027841945795\"\u003eA Google User\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAAiIyTEnkgKjKYFyQZKesopF4_dwAP6h0ynKq0nO5e9AelAo9D0IPqASptGAbZ999ZcOfPIQnlQYie5KtO45bIkSAMOowBkROYcJLdntbS0WhsNhhQJaG5lxU8aCUTuyjGEhBnHL_HnTImzwkwS4OHVSN9GhRO_IGFKamDj_8OEIL3i9MGaCWsXQ",
               "width" : 2048
            }
         ],
         "place_id" : "ChIJg-5cj9SxvJURkm6B2DlkKL0",
         "rating" : 5,
         "reference" : "ChIJg-5cj9SxvJURkm6B2DlkKL0"
      },
      {
         "formatted_address" : "Av. Sta Fe 1, B1642 Martínez, Buenos Aires, Argentina",
         "geometry" : {
            "location" : {
               "lat" : -34.4742948,
               "lng" : -58.51265829999999
            },
            "viewport" : {
               "northeast" : {
                  "lat" : -34.47292497010727,
                  "lng" : -58.51127897010728
               },
               "southwest" : {
                  "lat" : -34.47562462989271,
                  "lng" : -58.51397862989273
               }
            }
         },
         "name" : "Lollapalooza Argentina",
         "place_id" : "ChIJUQmrWaqxvJURScOzSiIIk9o",
         "rating" : 0,
         "reference" : "ChIJUQmrWaqxvJURScOzSiIIk9o"
      }
   ],
   "status" : "OK"
}
© www.soinside.com 2019 - 2024. All rights reserved.