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.eyJqdGkiOiJkOGVjOWM5OC00M2I4LTQ1MzQtOGE4ZS1mZjQzOTJhODkxNDMiLCJpYXQiOjE3MzI3NzI0NDEsImlzcyI6Imh0dHA6Ly92cC10c21jYWxjMDE6ODA4MC9LaVdlYlBvcnRhbC9hdXRoLyIsImF1ZCI6IjMyZGNlZWNlLTgyNmMtNGI5OC05YzJkLWIxNjk3OGYwY2E2YSIsImV4cCI6MTczMjg1ODg0MX0.A_rJ2YCrHMx8QfaBRMps-c7Fu6x_U4M7YSAZ0sgOWLCaiXaBQXlRtAvK4eDU1LTddytKaq9SXAa4XZDG68VjBL0KIzW-7JdIRLTrGg1Og5OLjbTYjAJmOsCw9cd-yFFxCeYwFbwiyM-l30PtE9SqgSrUWPRxp76P2_-T10IeY1FVA0I9uTDjLP1IzTo2SZ4CCH9gexB9hkmjTlegcqeb6ik80OgUIo-bO3450dP532Dbf6I7ZEOtvTx9bcMn4uaQq0KDrgLin5EqtUL9Ag4tLr2zAjTJtvmBVLU3qbtq35MLLfuyK3bkoq3RgR_neFynEho_qD5YM2wOc_aOWV0QVQ
#>
#> Attributes:
#> url: http://download.waterinfo.be/kiwis-auth/token
#> type: Bearer
#> expires: 2024-11-29 05:40:41 UTC
# get token via client
client <- paste0('MzJkY2VlY2UtODI2Yy00Yjk4LTljMmQtYjE2OTc4ZjBjYTZhOjRhZGE4',
'NzFhLTk1MjgtNGI0ZC1iZmQ1LWI1NzBjZThmNGQyZA==')
my_token <- get_token(client = client)
print(my_token)
#> Token:
#> eyJhbGciOiJSUzUxMiJ9.eyJqdGkiOiIyNDYxOTZmOC0zMTE3LTQ3MDgtOTI1Mi05OGJlNmMwNGI3YjciLCJpYXQiOjE3MzI3NzI0NDEsImlzcyI6Imh0dHA6Ly92cC10c21jYWxjMDE6ODA4MC9LaVdlYlBvcnRhbC9hdXRoLyIsImF1ZCI6IjMyZGNlZWNlLTgyNmMtNGI5OC05YzJkLWIxNjk3OGYwY2E2YSIsImV4cCI6MTczMjg1ODg0MX0.hsr41gXjYcL2Sb9YqgRBVnjM_7hUIkjX3oLRQyfKRbMieh6gQOFtG81NK7pYDT8jBfNFWvko99Ty7W5Oj4mmFGmQttQ_PHA4ULkT8idFCAY3U2miRlOSzMFRI_7RnLeuQFHSWnBRbpbvYxwkBF1gPRkz-kAq1rYN4IngqJsj6N1J0SST42aXQbC00lVBXzK-VeZZdUU0EBKYvVy8x_brF8lck0FkJ2kfFqvQGzacG7Ns7bLAu-20dGWEk3Un8RPV2WgSE90VH1gumBq8JRlVImDlMLG1p5bN8OvDjlxl8MayS4DI1wxK_EY3IrBSXJ19Z3M7Ly9fk_Szj6Fhbnwxiw
#>
#> Attributes:
#> url: http://download.waterinfo.be/kiwis-auth/token
#> type: Bearer
#> expires: 2024-11-29 05:40:41 UTC
is.expired(my_token)
#> [1] FALSE
expires.in
#> function (token)
#> {
#> UseMethod("expires.in", token)
#> }
#> <bytecode: 0x56488f560db8>
#> <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