我正在尝试使用Google和URLFetchApp解析来自Google调用的JSON结果。
我已经启用了Places并创建了一个API密钥,如果我将以下内容粘贴到Chrome浏览器中.
我收到:
{
"candidates" : [
{
"formatted_address" : "240 Exhibition St, Melbourne VIC 3000, Australia"
}
],
"status" : "OK"
}
然而,当我试图用谷歌脚本检索它的时候.
function mapAddress() {
var url = "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=telstra%20headoffice&inputtype=textquery&fields=formatted_address&key=VALID_KEY";
var response = UrlFetchApp.fetch(url,{muteHttpExceptions:true});
var json = response.getContentText();
var data = JSON.parse(json);
Logger.log(data.status);
Logger.log(response);
当我查看行刑记录的时候.
[19-12-13 10:43:50:300 AEDT] Starting execution
[19-12-13 10:43:50:666 AEDT] UrlFetchApp.fetch([https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=telstra%20headoffice&inputtype=textquery&fields=formatted_address&key=VALID_KEY, {muteHttpExcepti...) [0.354 seconds]
[19-12-13 10:43:50:666 AEDT] UrlFetchApp.HTTPResponse.getContentText() [0 seconds]
[19-12-13 10:43:50:668 AEDT] Logger.log([ZERO_RESULTS, []]) [0 seconds]
[19-12-13 10:43:50:669 AEDT] Logger.log([{
"candidates" : [],
"status" : "ZERO_RESULTS"
}
, []]) [0 seconds]
[19-12-13 10:43:50:670 AEDT] Execution succeeded [0.36 seconds total runtime]
我做错了什么?
发布于 2019-12-13 10:46:14
Places文档包含有关位置偏差的信息。默认情况下,它使用原始请求的IP地址。
https://developers.google.com/places/web-service/search#PlaceSearchRequests
我使用了基于澳大利亚的lat/log的位置偏差,现在起作用了。
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=telstra%20headoffice&inputtype=textquery&fields=place_id,formatted_address®ion=au&locationbias=circle:50000@-25.966828,134.537373&key=VALID_KEY
https://stackoverflow.com/questions/59314436
复制相似问题