Skip to contents

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)

Arguments

client

base64 encoded client containing the client id and client secret, seperated by :

client_id

client id string

client_secret

client secret string

token_url

url to get the token from

token

a token object

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.eyJqdGkiOiIwMTVkMDkwYS0yMTZmLTQ3NzUtYWZiMS0yYWUyZDNkZjQ0MDgiLCJpYXQiOjE3MzAxODE3MzcsImlzcyI6Imh0dHA6Ly92cC10c21jYWxjMDE6ODA4MC9LaVdlYlBvcnRhbC9hdXRoLyIsImF1ZCI6IjMyZGNlZWNlLTgyNmMtNGI5OC05YzJkLWIxNjk3OGYwY2E2YSIsImV4cCI6MTczMDI2ODEzN30.E3KNv04uqnM0Ak2PwHiIVaRfgZR7A7xr0CbgMLfXEODzVPLn09Uzkh6RnqzobWqiQ_RhZ5-JtLJJXf98jzTUxKfqiyQyEt85O_KR5HmjB1VcwtSoG6mLjGjlqpXohpbpp2eBg71-EaLm4Koj4sMBiYXQG-jL3MWDwLVxL8_5tEj8Fw9puURWhcvzzuK_FuxByZxjbALMPQxaShP9ILTuPcgjPzKqKWpNiNsOEBWci5J576hT_NdNcGZg-1CM-_mD_FcXjrDI7-KXss2w3Yoy81Y73AsWcs6Bdk6UFsfOv1BlOVXhRCGXseaC2JUjAN5E1vaZI-E0KA-Oog1cCOz9iw
#> 
#> Attributes:
#>  url: http://download.waterinfo.be/kiwis-auth/token
#>  type: Bearer
#>  expires: 2024-10-30 06:02:17 UTC

# get token via client
client <- paste0('MzJkY2VlY2UtODI2Yy00Yjk4LTljMmQtYjE2OTc4ZjBjYTZhOjRhZGE4',
                'NzFhLTk1MjgtNGI0ZC1iZmQ1LWI1NzBjZThmNGQyZA==')
my_token <- get_token(client = client)
print(my_token)
#> Token:
#> eyJhbGciOiJSUzUxMiJ9.eyJqdGkiOiIzNzU5OTQwMS00ZDIwLTRkZTYtYTg2Ni01MmViYjE5OGE1ZjEiLCJpYXQiOjE3MzAxODE3MzcsImlzcyI6Imh0dHA6Ly92cC10c21jYWxjMDE6ODA4MC9LaVdlYlBvcnRhbC9hdXRoLyIsImF1ZCI6IjMyZGNlZWNlLTgyNmMtNGI5OC05YzJkLWIxNjk3OGYwY2E2YSIsImV4cCI6MTczMDI2ODEzN30.CgCYjvlI3JuEgmZScqsvtCIbgtP0VHE7akgpDNjBdUSb57QLgVR5Z_MXlbSI9ide93wXLIOiHPtcwz5GjBpBxO5T4Je8piENANTUrZTCnPsGt1MNAE7Qkfnnwl1dIyKt2ZT7lBXKXtnJUZBgmg-7OQ1EqOuVJyrY0HICyeHex2whyMm2g61UujwuqLdctfF2kOQCrn9hcm8ZUtIgWr6ttQfRlFXuH7LNjkz9MSQWEp7W8ddnoCCASLzDc23rM0a-rk0vFwvk19xnzcBzjOBakAGaicbIFFBkDEeFIgVns0x_7D28kMxW7hzbp2HW4C1_cLMaG6hBBtQHdFyvnLcA1g
#> 
#> Attributes:
#>  url: http://download.waterinfo.be/kiwis-auth/token
#>  type: Bearer
#>  expires: 2024-10-30 06:02:17 UTC
is.expired(my_token)
#> [1] FALSE
expires.in
#> function (token) 
#> {
#>     UseMethod("expires.in", token)
#> }
#> <bytecode: 0x55ce37e06658>
#> <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