r - 运行调用结果
问题描述
我尝试运行此示例脚本,但是当我键入此命令时,我收到以下错误
austin_tx <- city_state("AUSTIN", "TEXAS")
Error in if (this.clean.resp$page_metadata$has_next_page == FALSE) { :
argument is of length zero
知道为什么会这样吗?
解决方案
在前面,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上的说明进行更新。
推荐阅读
- assertj - Assertj + 如何禁用堆栈跟踪
- swift - 使用 DateComponents 创建日期
- php - 在codeigniter中计算结果
- php - 仅显示特定的索引数组
- react-native - BottomTabNavigator 上的涟漪效应
- mysql - VB6 - 将数据从 mySQL 表插入访问表
- safari - Safari 应用程序扩展内容脚本未加载到 Safari 错误页面上?
- java - GenericUDAFResolver2 已被弃用,我们现在应该如何实现 UDAF?
- node.js - Expressjs - 将标头发送到客户端后无法设置标头
- r - 根据相邻列的值替换多列中的值