【问题标题】:Google Places API fetch returns status: 200 but no dataGoogle Places API 提取返回状态:200 但没有数据
【发布时间】:2021-10-17 00:05:46
【问题描述】:
 const response = await fetch(
    //`https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input=${textInput}&location=${latitude}%${longitude}&key=${apiKey}`,
    //`https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input=pizza%20near%20par&key=${apiKey}`,
    `https://maps.googleapis.com/maps/api/place/autocomplete/json?input=amoeba&types=establishment&location=37.76999%2C-122.44696&radius=500&key=${apiKey}`,
    {}
  );

  console.log("TEST: place response ", JSON.stringify(response));

我在网上找不到任何相关问题, 我尝试了几个直接从文档中的示例复制的不同端点,但都返回相同的响应:

{
   "type":"default",
   "status":200,
   "ok":true,
   "statusText":"",
   "headers":{
      "map":{
         "server":"scaffolding on HTTPServer2",
         "expires":"Sat, 16 Oct 2021 23:19:04 GMT",
         "server-timing":"gfet4t7; dur=92",
         "content-type":"application/json; charset=UTF-8",
         "alt-svc":"h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-T051=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"",
         "cache-control":"public, max-age=300",
         "x-xss-protection":"0",
         "content-encoding":"gzip",
         "date":"Sat, 16 Oct 2021 23:14:04 GMT",
         "x-frame-options":"SAMEORIGIN",
         "content-length":"526",
         "vary":"Accept-Language"
      }
   },
   "url":"https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input=pizza%20near%20par&key=MY_API_KEY",
   "bodyUsed":false,
   "_bodyInit":{
      "_data":{
         "size":6304,
         "offset":0,
         "blobId":"62109E2F-1D20-473B-94A5-2A3E7C664E9A",
         "type":"application/json",
         "name":"json",
         "__collector":{
            
         }
      }
   },
   "_bodyBlob":{
      "_data":{
         "size":6304,
         "offset":0,
         "blobId":"62109E2F-1D20-473B-94A5-2A3E7C664E9A",
         "type":"application/json",
         "name":"json",
         "__collector":{
            
         }
      }
   }
}

我在我的谷歌开发者控制台中启用了 Place API。 多谢!

【问题讨论】:

    标签: google-api google-places-api


    【解决方案1】:

    我忘记在响应中使用 .json()。

    const data = await response.json(); 
    console.log("TEST: place response ", data);
    

    https://github.com/github/fetch

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-08
      • 2014-02-11
      • 1970-01-01
      相关资源
      最近更新 更多