我是一个使用R语言处理API的新手。我看到另一个类似的帖子,但它使用的是API v6(目前正在维护中),而新的是v7。所以无论如何我都要把这个贴出来。
目标基于this documentation从HERE Maps API v7获取流量数据
问题我使用httr
包请求流量数据,代码如下
library(httr)
source("config.R")
# Set the API endpoint URL
url <- "https://data.traffic.hereapi.com/v7/flow"
# Set the required query parameters
in_area <- "circle:13.1,-43.1;r=10000"
location_referencing <- c("none", "shape")
min_jam_factor <- 5
max_jam_factor <- 8
functional_classes <- c(1, 2, 3, 4, 5)
# Set the headers
headers <- c("apiKey" = here_api_key,
"X-Request-Id" = "8230d7ad-3f1c-4191-a8dd-f3c42026da89")
# Construct the query string
query_string <- paste0(
"in=", in_area,
"&locationReferencing=", paste(location_referencing, collapse = ","),
"&minJamFactor=", min_jam_factor,
"&maxJamFactor=", max_jam_factor,
"&functionalClasses=", paste(functional_classes, collapse = ",")
)
# Create the complete URL with query string
complete_url <- paste0(url, "?", query_string)
# Send the GET request
response <- GET(complete_url, add_headers(headers))
字符串
返回错误401
$error
[1] "Unauthorized"
$error_description
[1] "No credentials found"
型
Question不是我的apiKey
代码写错了,就是我的API key访问不到流量数据。
所以,最有可能发生的事情是我写错了代码,是吗?
1条答案
按热度按时间7bsow1i61#
请打开该案例的支持工单。
亲切的问候