我正在学习使用带有R的httr
包和US Data Census API作为我的API的API。
当我通过在GET()
中手动输入URL发出请求时,请求有效。
try_using_manual<- httr::GET("https://api.census.gov/data/2014/pep/natstprc?get=STNAME,POP&DATE=7&for=state:01&key=XXXX")
> try_using_manual
Response [https://api.census.gov/data/2014/pep/natstprc?get=STNAME,POP&DATE=7&for=state:01&key=7e3d28d2d9facb45c12a0b63f9d31b709d917dda]
Date: 2018-12-08 03:08
Status: 200
Content-Type: application/json;charset=utf-8
Size: 65 B
[["STNAME","POP","DATE","state"],
当我尝试执行相同的请求,但通过GET()
函数构建参数时,我的请求失败。
> try_using_arg <- httr::GET(url = "https://api.census.gov/data/2014/pep/natstprc",
+ query = list("STNAME"=":*","POP"=":*","DATE"=7))
> try_using_arg
Response [https://api.census.gov/data/2014/pep/natstprc?STNAME=%3A%2A&POP=%3A%2A&DATE=7]
Date: 2018-12-08 03:20
Status: 400
Content-Type: text/plain;charset=ISO-8859-1
Size: 74 B
在STNAME
的{{1}}中看到关于如何调用这些变量POP
,DATE
,state
,try_using_manual
的想法吗?
任何帮助,我们将不胜感激!