as far as i know, the rinat
library hits the deprecated API. so i personally would not develop against that. instead, i would hit the current version of the API (currently, v1) directly or else use some module that hits the current API, such as spocc
.
it depends on the capabilities of module youâre using. if youâre hitting the API directly, definitely yes.
for me, usually the easiest thing to do when hitting the API directly is to go to https://www.inaturalist.org/users/api_token while youâre logged into inaturalist.org. youâll see a bit of text that looks something like {"api_token": "api.token.value"}
. this is a JSON web token (JWT). iâll copy the api.token.value
and use this as my bearer token in my Authorization header when i make my API requests. the JWT will expire every 24 hours. so youâll just need to get a new one if you want to do the same thing after it has expired. you donât want to share the JWT with anyone else or store it in a way that is insecure because anyone who has access to it will be able to do have full access to your account until the token expires.
if you want to have a more automated or secure workflow, itâs a more complicated setup. youâd have to go through the process of registering an iNaturalist application and then set up a flow to get an OAuth token and then a JWT using the OAuth token. (technically itâs possible to use the OAuth token to make some requests in place of the JWT, but itâs not something i would do because i believe iNat doesnât expire the OAuth token until you request another, and it could be a bigger deal if you lost control of it unknowingly than losing control of a JWT.)
âŚ
itâs not R, but if you want to avoid having to write something from scratch, youâre welcome to use my JupyterLite workbook to get observation data from the API. it runs a version of Python that can be run via JupyterLite directly in your browser, which can save you the work of setting up a special environment just to run scripts.
When running from JupyterLite, all your requests happen from your machine, and your changes and results get saved in your browserâs storage, which can then be downloaded to your machine, if you like.
in its simplest usage that includes user authorization, you would:
- open the workbook via JupyterLite in your browser.
- in the line that begins
jwt =
, set this equal to your JWT value (ex. jwt = 'api.token.value'
).
- in the line that begins
req_params_string =
, set the value equal to whatever parameters you would like to apply in your request. if youâre trying to specify a list of obs IDs, it would be something like req_params_string = 'id=10000,10001,10002'
- in the line that begins with
obs = await
, you would set get_all_pages=True
if you expect to get more than 30 observations, and use_authorization=True
- in the section that begins with
parse_fields = [
, define which fields you want to get in your results. iâve pre-defined a few fields that i thought might be generally useful. so you might be able to just uncomment or comment the fields youâre interested in or not interested in. in cases where a field might have multiple values per observation, iâve defined most of these to flatten the values (string multiple values together into one string) or else provide some aggregate result such as a count. youâre welcome to adapt these definitions in case you need something that hasnât been pre-defined.
- then run each cell from the top, or run all. in your case, you want the results in a CSV. so you donât have to run anything past the âWrite Data to CSVâ section. the resulting CSV file will be stored in browser storage, and youâll be able to see it in the JupyterLite file navigation tree on the left side of the page. you can click on it to view it in the JupyterLite interface, or you can right-click and download the file to your machine so that you can work with it in your own applications on your machine.
any changes to the workbook you make should get automatically saved along the way in browser storage as you run things or as you click the save button. if you want to preserve the original workbook so that you can start over easily, itâs cleanest if, before step 1 above, you find the file in the file navigation tree and save a new version, and then work in that new version. your work will be preserved across browsing sessions as long as you donât clear your storage. or if you do all your work in a private browsing session, everything will always reset back whenever you start a new private browsing session. just remember that youâll want to download any workbooks to your machine if you want to preserve them long-term.