getApiKey: Get the API key

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

Get the API key(s). It is usually used in a function call chain that makes use of Google or Baidu map APIs, e.g., geocode.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
getApiKey(app = c("google", "baidu", "gaode", "ipstack", "ipify",
  "ipinfo"), overide = FALSE, drop = TRUE, ...)

get_api_key(app = c("google", "baidu", "gaode", "ipstack", "ipify",
  "ipinfo"), overide = FALSE, drop = TRUE, ...)

setApiKey(app = c("google", "baidu", "gaode", "ipstack", "ipify",
  "ipinfo"), key = NULL, gen_pem = FALSE, ...)

set_api_key(app = c("google", "baidu", "gaode", "ipstack", "ipify",
  "ipinfo"), key = NULL, gen_pem = FALSE, ...)

Arguments

app

character vector of the application name for the API, either 'google', 'baidu', 'gaode', 'ipstack', 'ipinfo' or 'ipify'.

overide

logical, whether flush the stored API key and call a GUI wizard to enter a new one. Default FALSE to enable reusing the keys.

drop

logical, whether coerce the result to a named vector. Default TRUE. If FALSE, you will get a named list instead.

...

other arguments. For instance,

Args of input_char() to call a GUI wizard for input
  • prompt: prompt label of the GUI frame

  • caption: caption of the GUI window

  • default: default value for the input box

  • gui: 'Rstudioapi', 'Gwidgets' or 'WinGui'.

key

character vector or list, value(s) of the API key(s). You can directly assign corresponding values here. Default NULL (gui mode), indicating that a GUI wizard will be launched for you to enter the API key respectively. Generally, gui mode is more secure.

gen_pem

logical, whether generate .pem files in the tempdir(). Default FALSE.

Details

If the encrpyted API key(s) have been previously stored in the package hidden environment pkgenv$API_KEY, the function will extract it after an auto decryption. If not previously stored in pkgenv, a GUI wizard (inputChar) will be launched for you to enter the key(s).
When you encounter an API error, please either

Value

invisible. You must assign it to an object.

Note

Do not disclose the key to anyone as it may cause data leakage.

Author(s)

Yiying Wang, wangy@aetna.com

See Also

input_char(), get_raw_pwd()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
get_api_key('google', gui='WinGui')
get_api_key()  # you will get all the api keys

# if the api keys have been written to .pem files
set_api_key('baidu', <YOUR BAIDU API KEY>, gen_pem=TRUE)
key <- decrypt_it(get_raw_pwd(pem='baidu'))

## End(Not run)
## Not run: 
#' key <- <YOUR BAIDU API KEY>  # not recommended: keys are exposed
setApiKey('baidu', key=key)
setApiKey('baidu', key=NULL)  # recommended

# set multiple API keys
set_api_key(app=c("google", "baidu", "gaode", "ipstack", "ipinfo", "ipify"),
            key=<THE CORRESPONDING KEY CHARACTER VECTOR>)  # not recommended
set_api_key()  # pop up a series of GUI windows to input all the API keys

## End(Not run)

madlogos/aseskit documentation built on June 26, 2019, 12:17 a.m.