从终端向Google的地理编码API发送请求

时间:2011-12-19 22:02:44

标签: api unix geocoding wget

我正在尝试对大量数据进行地理编码。我有很多机器可以分散负载(这样我每天就不会超过每个IP地址2,500个请求)。我使用脚本来使用wget或cURL发出请求。但是,wget和cURL都会产生相同的“请求被拒绝”消息。话虽这么说,当我从我的浏览器发出请求时,它完美无缺。示例请求是:

wget http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true

结果输出为:

    [1] 93930
05:00 PM ~: --2011-12-19 17:00:25--  http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA
Resolving maps.googleapis.com... 72.14.204.95
Connecting to maps.googleapis.com|72.14.204.95|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/json]
Saving to: `json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA'

    [ <=>                                   ] 54          --.-K/s   in 0s      

2011-12-19 17:00:25 (1.32 MB/s) - `json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA' saved [54]

它写的文件只包含:

{
   "results" : [],
   "status" : "REQUEST_DENIED"
}

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:3)

'&amp;'分隔地址和传感器参数的字符不会传递给wget命令,而是告诉shell在后台运行wget。生成的查询缺少必需的“传感器”parameter,应根据您的输入将其设置为true或false。

wget "http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false"