Retrieve a fresh waterinfo token. A token is not required to get started, see Details section for more information.
Usage
get_token(
client = NULL,
client_id = NULL,
client_secret = NULL,
token_url = "http://download.waterinfo.be/kiwis-auth/token"
)
is.expired(token)
expires.in(token)
Value
An object of class token containing the token string with the token_url, token type and moment of expiration as attributes.
Details
Notice you do not need to get a token right away to download data. For limited and irregular downloads, a token will not be required. The amount of data downloaded from waterinfo.be is limited via a credit system. When you require more extended data requests, request a download token.
Either client or client_id and client_secret need to be passed as arguments. If provided, client is always used. Tokens remain valid for 24 hours, after which a fresh one must be acquired. To limit load on the server, token objects should be reused as much as possible until expiration in stead of creating fresh ones for each call.
The client_id and client_secret provided in the examples are for test purposes, get your very own client via hydrometrie@waterinfo.be.
Examples
# Get token via client_id and client_secret
client_id <- '32dceece-826c-4b98-9c2d-b16978f0ca6a'
client_secret <- '4ada871a-9528-4b4d-bfd5-b570ce8f4d2d'
my_token <- get_token(client_id = client_id,client_secret = client_secret)
print(my_token)
#> Token:
#> eyJhbGciOiJSUzUxMiJ9.eyJqdGkiOiI5MmFjYWFmYS00MWFhLTQ4YWYtYmI3ZS02MzM0YWQyNTIzOGYiLCJpYXQiOjE3MjUwMTA0ODEsImlzcyI6Imh0dHA6Ly92cC10c21jYWxjMDE6ODA4MC9LaVdlYlBvcnRhbC9hdXRoLyIsImF1ZCI6IjMyZGNlZWNlLTgyNmMtNGI5OC05YzJkLWIxNjk3OGYwY2E2YSIsImV4cCI6MTcyNTA5Njg4MX0.Wvv0jqeKG24CZiIgtdSnlmeyMJJY4N1UuFiGU3nll0QLsmrKAxyNlH3F4s5e99721yRMf7EruWhmpFrO31MaTDouul93MlbHyN0Mu_qu50vKwcyJUtFc1p_unWEwAqjVfZqlvSFq4iDKhY5hgScm7-QsVMpaAzfx6pCj2CY7h9FVUXE_VR5qnueMmPMhMyIK7_fUmcJ-vPjIIUn3n9f7Ae3F0SmN-Xco6L3oykNuuQT_EVaMm256fdWaGQgmYS0t4vdGUjksb4GGBeb0-qdYijhUps0dFsI2RvsFZooPFdrkBU8fn0YG6iS5NOPRrHXZHYeRtdKB7rGno_6nPG20sA
#>
#> Attributes:
#> url: http://download.waterinfo.be/kiwis-auth/token
#> type: Bearer
#> expires: 2024-08-31 09:34:41 UTC
# get token via client
client <- paste0('MzJkY2VlY2UtODI2Yy00Yjk4LTljMmQtYjE2OTc4ZjBjYTZhOjRhZGE4',
'NzFhLTk1MjgtNGI0ZC1iZmQ1LWI1NzBjZThmNGQyZA==')
my_token <- get_token(client = client)
print(my_token)
#> Token:
#> eyJhbGciOiJSUzUxMiJ9.eyJqdGkiOiI4NWJmYzRkNi05ZGEwLTRmYTUtOGZkYy00NjhmZDhhODJjNTIiLCJpYXQiOjE3MjUwMTA0ODEsImlzcyI6Imh0dHA6Ly92cC10c21jYWxjMDE6ODA4MC9LaVdlYlBvcnRhbC9hdXRoLyIsImF1ZCI6IjMyZGNlZWNlLTgyNmMtNGI5OC05YzJkLWIxNjk3OGYwY2E2YSIsImV4cCI6MTcyNTA5Njg4MX0.TZaR3l6nLCh4aOvzqRdcvTZh3XPGz7_DExRSS-4C2uEfcD7SJbP69J1DDv5AOspF994I0SHGSfBN9KhyDffshGz_UcjE1Wp0iJsAibt_8Z99NVU20gJx4BP9CFUrwQyWDxELb6_FvB5j80rkmh81Kfil2zb1cN9VvkSfbXjvy8cLQA6Bpk75pDS0_hWBxBB_D2Pklop9ib-vcabwRJOvXhv6XjCx55pdFPZrjebXrLv4ku4OqsoWhEgladBTJXkKuxDbBqItSCzGXOxuL51EZ0eGUdl3kfOTEL9AiZnRo8RoWZmaWU4DgzyODT1U3B8jwNGh4P4TKClVle3cof28zA
#>
#> Attributes:
#> url: http://download.waterinfo.be/kiwis-auth/token
#> type: Bearer
#> expires: 2024-08-31 09:34:41 UTC
is.expired(my_token)
#> [1] FALSE
expires.in
#> function (token)
#> {
#> UseMethod("expires.in", token)
#> }
#> <bytecode: 0x5601ede30f50>
#> <environment: namespace:wateRinfo>
# Use the token when requesting for data (i.e. get_* functions), e.g.
get_stations(variable_name = "verdamping_monteith", token = my_token)
#> ts_id station_latitude station_longitude station_id station_no
#> 1 94310042 51.02263 2.970584 12206 ME01_003
#> 2 94544042 51.20300 5.439589 12213 ME11_002
#> 3 94516042 50.73795 5.141976 12211 ME09_012
#> 4 94530042 51.16224 4.845708 12212 ME10_011
#> 5 94474042 51.24379 4.266912 12208 ME04_001
#> 6 94460042 51.27226 3.728299 12207 ME03_017
#> 7 94488042 50.86149 3.411318 12209 ME05_019
#> 8 94502042 50.88663 4.094898 12210 ME07_006
#> station_name stationparameter_name parametertype_name
#> 1 Zarren_ME pET PET
#> 2 Overpelt_ME pET PET
#> 3 Niel-bij-St.-Truiden_ME pET PET
#> 4 Herentals_ME pET PET
#> 5 Melsele_ME pET PET
#> 6 Boekhoute_ME pET PET
#> 7 Waregem_ME pET PET
#> 8 Liedekerke_ME pET PET
#> ts_unitsymbol dataprovider
#> 1 mm VMM
#> 2 mm VMM
#> 3 mm VMM
#> 4 mm VMM
#> 5 mm VMM
#> 6 mm VMM
#> 7 mm VMM
#> 8 mm VMM