Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Status 401; Unauthorized; No permission #157

Closed
technocrat opened this issue Jul 3, 2023 · 8 comments · Fixed by #159
Closed

Bug: Status 401; Unauthorized; No permission #157

technocrat opened this issue Jul 3, 2023 · 8 comments · Fixed by #159
Labels
bug Something isn't working

Comments

@technocrat
Copy link

Describe the bug
here endpoint rejects API key

Unless I am wrong that the 'single-bearer credential' is the API key, authentication is consistently failing. If the API key is something other than here.access.key.id or here.access.key.secret, that's unclear in the example given. I've been unable to discover a third way of creating tokens on their developer website.

Reproducible example

# libraries
library(dplyr)
library(hereR)

# health facility
data <- read.csv("https://raw.githubusercontent.com/isaid-hi/bipi.datalab/main/2023.06.24_%234%20Hospital%20Access/hospitals.csv")

# hospital only
hospitals <- data %>% filter(Type %in% "Rumah Sakit")
hospital_sf <- st_as_sf(x = hospitals,
                        coords = c("Longitude", "Latitude"),
                        crs = "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")

# get isoline ----
## here api setup ----
set_key("here.access.key.id") # either this or the longer here.access.key.secret

## build isoline ----
### isoline for hospitals ----
isochrones_all <- isoline(
  poi = hospital_sf,
  range = seq(10, 30, 10) * 60,
  range_type = "time",
  datetime <- as.POSIXct(paste0(Sys.Date()," 10:00")) 
) %>%
  mutate(name = paste0((range - 600) / 60," to ", range / 60, " mins"))

Expected behavior
Following `set_key("some_token") request silently authenticates and returns results

Optionally: R session info
Not relevant

@technocrat technocrat added the bug Something isn't working label Jul 3, 2023
@isaid-hi
Copy link

isaid-hi commented Jul 4, 2023

I noticed that traffic flow API v6 is on maintenance. While they have API v7 for traffic flow. Looked like hereR haven't used the API v7, have it?

@technocrat
Copy link
Author

technocrat commented Jul 4, 2023 via email

@munterfi
Copy link
Owner

munterfi commented Jul 4, 2023

Thanks for reporting, the issue you're experiencing is likely caused by an invalid API key.

Go to the projects view on HERE developer. Then create a new project and select REST. There you should be able to create an API key using the button “Create API key”. Copy paste the key and set it using set_key(...). Or alternatively export it to the environment export HERE_API_KEY=<YOUR-VALID-KEY-HERE>.

# libraries
library(dplyr)
library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(hereR)

# use a valid key
# set_key("<KEY>")

# print some logs
set_verbose(TRUE)

# health facility
data <- read.csv("https://raw.githubusercontent.com/isaid-hi/bipi.datalab/main/2023.06.24_%234%20Hospital%20Access/hospitals.csv")

# hospital only
hospitals <- data |> filter(Type %in% "Rumah Sakit")
hospital_sf <- st_as_sf(
  x = hospitals,
  coords = c("Longitude", "Latitude"),
  crs = 4326
)

# isoline for hospitals
isochrones_all <- isoline(
  poi = hospital_sf,
  range = seq(10, 30, 10) * 60,
  range_type = "time",
  datetime <- as.POSIXct(paste0(Sys.Date(), " 10:00"))
)
#> Sending 2 request(s) with 1 RPS to: 'https://isoline.router.hereapi.com/v8/isolines?...'
#> Received 2 response(s) with total size: 11.7 Kb

# sort descending, convert units
isochrones_all <- isochrones_all |>
  arrange(desc(range)) |>
  mutate(name = paste0((range - 600) / 60, " to ", range / 60, " mins"))

isochrones_all
#> Simple feature collection with 6 features and 6 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 106.713 ymin: -6.876068 xmax: 106.9547 ymax: -6.421509
#> Geodetic CRS:  WGS 84
#>   id rank           departure             arrival range
#> 1  1    3 2023-07-04 10:00:00 2023-07-04 10:30:00  1800
#> 2  2    3 2023-07-04 10:00:00 2023-07-04 10:30:00  1800
#> 3  1    2 2023-07-04 10:00:00 2023-07-04 10:20:00  1200
#> 4  2    2 2023-07-04 10:00:00 2023-07-04 10:20:00  1200
#> 5  1    1 2023-07-04 10:00:00 2023-07-04 10:10:00   600
#> 6  2    1 2023-07-04 10:00:00 2023-07-04 10:10:00   600
#>                         geometry          name
#> 1 POLYGON ((106.762 -6.558151... 20 to 30 mins
#> 2 POLYGON ((106.7142 -6.79332... 20 to 30 mins
#> 3 POLYGON ((106.7978 -6.73667... 10 to 20 mins
#> 4 POLYGON ((106.7334 -6.77410... 10 to 20 mins
#> 5 POLYGON ((106.8314 -6.60003...  0 to 10 mins
#> 6 POLYGON ((106.7639 -6.77581...  0 to 10 mins

mapview::mapview(isochrones_all, zcol = "name")

Screenshot 2023-07-04 at 13 14 10

I hope this helps?

@isaid-hi
Copy link

isaid-hi commented Jul 4, 2023

Thanks for the response. Actually this potential bug starts here in Posit Community.
The original issue is not the isoline function, but the flow function.

With the exact same API key, isoline as the code above was working perfectly. But the flow function not.

library(hereR)
set_key(here_api_key)
flow(aoi, min_jam_factor = 0, url_only = FALSE)

it return error like this

Warning messages:
1: In .parse_response(i, out$responses()[[i]]) :
  https://traffic.ls.hereapi.com/traffic/6.2/flow.json: Request 'id = 1' failed. 
  Status 403; Forbidden; Request forbidden -- authorization will not help.
2: In .parse_response(i, out$responses()[[i]]) :
  https://traffic.ls.hereapi.com/traffic/6.2/flow.json: Request 'id = 2' failed. 
  Status 403; Forbidden; Request forbidden -- authorization will not help.

@technocrat
Copy link
Author

technocrat commented Jul 4, 2023 via email

@technocrat
Copy link
Author

Still no success. The documents suggested that an API Access key, as opposed to an OA token would be available by signing up for fremium, and that created fremium app but still only the option to create an OA token, which doesn't work, But then it appears that applications needed to be migrated from the old deveoper.here.com to the new platform.here.com, which requires a separate account. And then after signing into the platform account links to documentation go back to the ifi. In any event, not one of the OA tokens work and there's a different way to create a different kind of token, called API I'm stumped. The return from flow() doesn't pass access either.

I'm sure that {hereR} will work well once the credentials can be satisfied, but I'm going to give it a rest for now.

@isaid-hi
Copy link

isaid-hi commented Jul 8, 2023

I'm actually still waiting for Munterfi's response regarding the error in flow function. Have you test it @munterfi ?
Note that the same API Key works for isoline but not for flow fuction.

For clearer case, I move to the new issue #158

@munterfi
Copy link
Owner

Sorry for the late reply, I was off some days.

HERE has introduced the HERE Platform as a successor to HERE Developer. The process to create an API key has changed slightly and differs from the description in the hereR package vignette:

  1. Signup for the HERE Platform
  2. Create new App using the Credentials Manager
  3. Select the Credentials tab, then go to "API Keys" and click "Create API key"
  4. Copy the API key and set it in the R session with hereR::set_key()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants