首页 > 解决方案 > 运行调用结果

问题描述

我尝试运行示例脚本,但是当我键入此命令时,我收到以下错误

austin_tx <- city_state("AUSTIN", "TEXAS")

Error in if (this.clean.resp$page_metadata$has_next_page == FALSE) { : 
  argument is of length zero

知道为什么会这样吗?

标签: rapi

解决方案


在前面,API 发生了变化。

端点已被删除。有关当前支持的端点,请参阅https://api.usaspending.gov/docs/endpoints ,或https://github.com/fedspendingtransparency/usaspending-api报告问题。

我是如何发现这个的:

> debug(GET_all_pages) # the error indicates code found in this function
> austin_tx <- city_state("AUSTIN", "TEXAS")
> austin_tx <- city_state("AUSTIN", "TEXAS")
debugging in: GET_all_pages(PATH = "/api/v1/transactions/", QUERY = list(place_of_performance__city_name = CITY_NAME, 
    place_of_performance__state_name = STATE_NAME))
debug at #1: { ...
Browse[2]> n                                              # 'n' --> step to the next expression
debug at #3: pages <- list()
Browse[2]> n
debug at #5: url <- modify_url("https://api.usaspending.gov", path = PATH, 
    query = QUERY)
Browse[2]> n
debug at #10: raw.resp <- GET(url)
Browse[2]> n
debug at #11: if (http_type(raw.resp) != "application/json") {
    stop("API did not return json. Check 'status code = 200'", 
        call. = FALSE)
}
Browse[2]> n
debug at #15: this.char.resp <- rawToChar(raw.resp$content)
Browse[2]> n
debug at #17: this.clean.resp <- fromJSON(this.char.resp, flatten = TRUE)
Browse[2]> n

因为我们知道这是导致问题的对象,所以我停止在这里并查看变量。

Browse[2]> str(this.clean.resp)
List of 1
 $ detail: chr "Endpoint has been removed. Please refer to https://api.usaspending.gov/docs/endpoints for currently supported e"| __truncated__

您引用的文档已过期,需要按照https://api.usaspending.gov/docs/endpoints上的说明进行更新。


推荐阅读