| faostat_login | R Documentation |
Authenticates with the FAOSTAT API and stores the access token for the current session. Credentials are resolved in this order:
Arguments passed directly to the function.
The FAOSTAT_USER and FAOSTAT_PASSWORD environment
variables (set them in ‘~/.Renviron’ to avoid storing credentials
in scripts).
An interactive prompt (email via readline(), password via
rstudioapi::askForPassword() when available, otherwise
readline()).
API calls (get_faostat_bulk() etc.) trigger faostat_login()
automatically when no token is present, so explicit calls are optional.
faostat_login(
username = Sys.getenv("FAOSTAT_USER"),
password = Sys.getenv("FAOSTAT_PASSWORD"),
base_url = "https://faostatservices.fao.org/api/v1"
)
username |
character. Your FAOSTAT account email. Defaults to the
|
password |
character. Your FAOSTAT account password. Defaults to the
|
base_url |
character. Base URL for FAOSTAT authentication. |
## Not run:
# Simplest usage — prompts for credentials interactively if not set:
crop_production <- get_faostat_bulk(code = "QCL", data_folder = "data_raw")
# Silent usage — set in ~/.Renviron (run usethis::edit_r_environ() to open it):
# FAOSTAT_USER=your@email.com
# FAOSTAT_PASSWORD=yourpassword
crop_production <- get_faostat_bulk(code = "QCL", data_folder = "data_raw")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.