I've seen a bunch of tutorial to get HERE map, but those are using API v6 (currently
on maintenance) while the new one, that I wanna use, is v7. So I post this anyway.
GOAL
Get traffic flow data from HERE Maps API v7 based on this documentation
Problem
I'm using httr
package to request the traffic flow data with the following code
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))
It return error 401
$error
[1] "Unauthorized"
$error_description
[1] "No credentials found"
Question
It's either I write the code for the apiKey
incorrectly or my API key have no access to traffic flow data.
- I'm sure my API key is correct because I've tried to request
isoline()
data viahereR
package like in this code up to line 33 - I'm sure that traffic flow can be accessed using base plan API as it stated here
So what's wrong with my code?