munterfi/hereR

Error with Geocode

ningistine7 opened this issue · 3 comments

Hello,
System : Windows 10, R 3.6

I just took the exemple :
geocode(c("Schweighofstrasse 190, Zürich, Schweiz", "Hardstrasse 48, Zürich, Schweiz"))
and I got this error :
NULL
Warning messages:
1: In (function (res) : Request 'id = 1' failed: Status 401.
2: In (function (res) : Request 'id = 2' failed: Status 401.

The HTTP Status Code 401 means “Unauthorized”. See RFC 7235: ”The 401 (Unauthorized) status code indicates that the request has not been applied because it lacks valid authentication credentials for the target resource.”

Therefore I assume that the API key you are using is not valid.

Example with an invalid key:

library(hereR)
set_key("Not_a_valid_key")
geocode(c("Schweighofstrasse 190, Zürich, Schweiz", "Hardstrasse 48, Zürich, Schweiz"))
#> Warning in (function (res) : Request 'id = 2' failed: Status 401.
#> Warning in (function (res) : Request 'id = 1' failed: Status 401.
#> NULL

With a valid key:

set_key("<YOUR VALID KEY>")
geocode(c("Schweighofstrasse 190, Zürich, Schweiz", "Hardstrasse 48, Zürich, Schweiz"))
#> Simple feature collection with 2 features and 11 fields
#> geometry type:  POINT
#> dimension:      XY
#> bbox:           xmin: 8.50741 ymin: 47.35959 xmax: 8.51201 ymax: 47.37994
#> epsg (SRID):    4326
#> proj4string:    +proj=longlat +datum=WGS84 +no_defs
#>   id                                            address            street
#> 1  1 Schweighofstrasse 190, 8045 Zürich Zürich, Schweiz Schweighofstrasse
#> 2  2        Hardstrasse 48, 8004 Zürich Zürich, Schweiz       Hardstrasse
#>   houseNumber postalCode district   city county state country  type
#> 1         190       8045  Kreis 3 Zürich Zürich    ZH     CHE point
#> 2          48       8004  Kreis 4 Zürich Zürich    ZH     CHE point
#>                   geometry
#> 1 POINT (8.50741 47.35959)
#> 2 POINT (8.51201 47.37994)
Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.6.2 (2019-12-12)
#>  os       macOS Catalina 10.15.3      
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  de_CH.UTF-8                 
#>  ctype    de_CH.UTF-8                 
#>  tz       Europe/Zurich               
#>  date     2020-02-16                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 3.6.0)
#>  backports     1.1.5   2019-10-02 [1] CRAN (R 3.6.0)
#>  callr         3.4.0   2019-12-09 [1] CRAN (R 3.6.0)
#>  class         7.3-15  2019-01-01 [1] CRAN (R 3.6.2)
#>  classInt      0.4-2   2019-10-17 [1] CRAN (R 3.6.0)
#>  cli           2.0.0   2019-12-09 [1] CRAN (R 3.6.0)
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 3.6.0)
#>  curl          4.3     2019-12-02 [1] CRAN (R 3.6.0)
#>  data.table    1.12.8  2019-12-09 [1] CRAN (R 3.6.0)
#>  DBI           1.1.0   2019-12-15 [1] CRAN (R 3.6.0)
#>  desc          1.2.0   2018-05-01 [1] CRAN (R 3.6.0)
#>  devtools      2.2.1   2019-09-24 [1] CRAN (R 3.6.0)
#>  digest        0.6.23  2019-11-23 [1] CRAN (R 3.6.0)
#>  e1071         1.7-3   2019-11-26 [1] CRAN (R 3.6.0)
#>  ellipsis      0.3.0   2019-09-20 [1] CRAN (R 3.6.0)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 3.6.0)
#>  fansi         0.4.0   2018-10-05 [1] CRAN (R 3.6.0)
#>  fs            1.3.1   2019-05-06 [1] CRAN (R 3.6.0)
#>  glue          1.3.1   2019-03-12 [1] CRAN (R 3.6.0)
#>  hereR       * 0.3.1   2020-01-29 [1] CRAN (R 3.6.2)
#>  htmltools     0.4.0   2019-10-04 [1] CRAN (R 3.6.0)
#>  jsonlite      1.6     2018-12-07 [1] CRAN (R 3.6.0)
#>  KernSmooth    2.23-16 2019-10-15 [1] CRAN (R 3.6.2)
#>  knitr         1.26    2019-11-12 [1] CRAN (R 3.6.0)
#>  magrittr      1.5     2014-11-22 [1] CRAN (R 3.6.0)
#>  memoise       1.1.0   2017-04-21 [1] CRAN (R 3.6.0)
#>  pkgbuild      1.0.6   2019-10-09 [1] CRAN (R 3.6.0)
#>  pkgload       1.0.2   2018-10-29 [1] CRAN (R 3.6.0)
#>  prettyunits   1.0.2   2015-07-13 [1] CRAN (R 3.6.0)
#>  processx      3.4.1   2019-07-18 [1] CRAN (R 3.6.0)
#>  ps            1.3.0   2018-12-21 [1] CRAN (R 3.6.0)
#>  R6            2.4.1   2019-11-12 [1] CRAN (R 3.6.0)
#>  Rcpp          1.0.3   2019-11-08 [1] CRAN (R 3.6.0)
#>  remotes       2.1.0   2019-06-24 [1] CRAN (R 3.6.0)
#>  rlang         0.4.2   2019-11-23 [1] CRAN (R 3.6.0)
#>  rmarkdown     2.0     2019-12-12 [1] CRAN (R 3.6.0)
#>  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 3.6.0)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 3.6.0)
#>  sf            0.8-0   2019-09-17 [1] CRAN (R 3.6.0)
#>  stringi       1.4.5   2020-01-11 [1] CRAN (R 3.6.0)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 3.6.0)
#>  testthat      2.3.1   2019-12-01 [1] CRAN (R 3.6.0)
#>  units         0.6-5   2019-10-08 [1] CRAN (R 3.6.0)
#>  usethis       1.5.1   2019-07-04 [1] CRAN (R 3.6.0)
#>  withr         2.1.2   2018-03-15 [1] CRAN (R 3.6.0)
#>  xfun          0.11    2019-11-12 [1] CRAN (R 3.6.0)
#>  yaml          2.2.0   2018-07-25 [1] CRAN (R 3.6.0)
#> 
#> [1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library

yes thank you very much for your response :)

I don't know how I deleted a character in the api key, sorry for disturbing

I've got a similar problem, but with a different code:

geocode(c("Schweighofstrasse 190, Zurich, Switzerland", "Hardstrasse 48, Zurich, Switzerland"))
NULL
Warning messages:
1: In (function (res) : Request 'id = 2' failed: Status 400.
2: In (function (res) : Request 'id = 1' failed: Status 400.

Status 400 means Bad Request....

Any ideas?