Please fill out the following sections to the best of your ability, it will help us investigate bugs if we have this information at the outset. Screenshots are especially helpful, so please provide those if you can.
Platform iOS
Browser, Firefox/R
Description of problem Hello, I am exploring the usage of API’s through iNaturalist from scratch in R (Not using any packages). I had code that worked and I am afraid that I have accidentally created too many API tokens, that now my code will not execute. Is there a way to get around this? Will the account reset after a certain amount of time to generate an API token that will work again? Is there a limit?
R code below:
Install and load required packages
library(httr)
library(jsonlite)
Define the iNaturalist API endpoint
inat_api_url ← “https://api.inaturalist.org/v1”
API token:
api_token ← ‘token is here’
Set the API token in the HTTP headers
headers ← add_headers(Authorization = paste(“Bearer”, api_token))
Test the connection by retrieving user information
response ← GET(url = paste0(inat_api_url, “/users/me”), headers = headers)
Check if the request was successful
if (http_status(response)$status == 200) {
Parse the response content
user_info ← content(response, as = “parsed”)
Print user information
cat(“Connected to iNaturalist API\n”)
cat(“User ID:”, user_info$results[[1]]$id, “\n”)
cat(“User Login:”, user_info$results[[1]]$login, “\n”)
} else {
cat(“Failed to connect to iNaturalist API. Check your API token and try again.\n”)
}
Response [https://api.inaturalist.org/v1/users/me]
Date: 2024-03-28 15:43
Status: 401
Content-Type: application/json; charset=utf-8
Size: 37 B