Using the iNaturalist API

804 views
Skip to first unread message

Max Caplow

unread,
Jul 30, 2015, 7:05:57 PM7/30/15
to iNaturalist
Hi, 

I have a large number of observations (about 500) that I would like to upload to an iNaturalist project.  I have them stored in a database on my computer, so I would love to be able to use the API in order to post these observations so I don't have to do 500 by hand.  I have been using python for our processing and analysis, and have therefore been trying to use it for the API calls as well. Currently, I am having trouble getting an oauth2 access token, and would love some help on how exactly I am supposed to format my POST request.  My code looks like this:

import oauth2 as oauth 
 
site = "https://www.inaturalist.org"
access_token_url = "https://www.inaturalist.org/oauth/token"
consumer_key = 'removed for security'
consumer_secret = 'removed for security'

oauth_verifier = 'removed for security'


params = {
    'client_id': consumer_key,
    'client_secret': consumer_secret,
    'code': oauth_verifier,
    'redirect_uri': 'http://www.example.com/',
    'grant_type': 'authorization_code'} 
 
consumer = oauth.Consumer(consumer_key, consumer_secret)
client = oauth.Client(consumer)
resp, content = client.request(access_token_url, "POST",  body=str(paramsXML))


print resp
print content

The exact error I am getting is "AttributeError: 'dict' object has no attribute 'split'" 
I have also tried sending the parameters in other formats such as XML, but the API responds saying i have a malformed request.

Hope somebody else who has gotten this working with python as well can help.
Thanks!

Sincerely,

Max

Ken-ichi

unread,
Jul 31, 2015, 6:48:11 PM7/31/15
to inaturalist
I don't know about using the oauth2 package for Python,
body=str(paramsXML) seems a bit suspicious, and I wouldn't be
surprised if the oauth2 package provides a more abstracted interface
to retrieving an access token then specifying all those POST params
like you're doing.

I don't know if it will help, but here's a Python version of one of
our Ruby examples from the docs:
https://gist.github.com/kueda/53ef93159c64de96ddc2. The Resource Owner
Password Credentials flow might be more appropriate for scripts like
the one you're writing. The Authorization Code Flow is more for
contexts in which your application interacts with iNat on behalf of
the user, and it needs to get permission to do so without knowing
confidential info like a password.
> --
> You received this message because you are subscribed to the Google Groups
> "iNaturalist" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to inaturalist...@googlegroups.com.
> To post to this group, send email to inatu...@googlegroups.com.
> Visit this group at http://groups.google.com/group/inaturalist.
> For more options, visit https://groups.google.com/d/optout.

Some Else

unread,
Jan 16, 2019, 5:49:09 AM1/16/19
to iNaturalist
Hi Max,

Did you in the end succeed in uploading your observations to iNaturlalist with a python script ?

Thanks in advance
Me

Op vrijdag 31 juli 2015 01:05:57 UTC+2 schreef Max Caplow:

Nicolas Noé

unread,
Jan 16, 2019, 6:39:12 AM1/16/19
to inatu...@googlegroups.com

Hi,

It's still in an early stage of development, but pyinaturalist (https://pyinaturalist.readthedocs.io/en/latest/?badge=latest) can be used to easily upload observations from Python to iNaturalist. See "For authenticated API calls, you first need to obtain a token for the user:" and "Create a new observation" from the link above.

Don't hesitate to ask if you encounter any issue or need a better example (I'm the developer).

Cheers,

Nico

Le 16/01/19 à 11:49, Some Else a écrit :
--
You received this message because you are subscribed to the Google Groups "iNaturalist" group.
To unsubscribe from this group and stop receiving emails from it, send an email to inaturalist...@googlegroups.com.
To post to this group, send email to inatu...@googlegroups.com.

Some Else

unread,
Jan 19, 2019, 1:04:24 PM1/19/19
to iNaturalist
Two questions about  pyinaturalist 
1. What is the input format for observations you want to add to iNaturalist?
2. Can you add common names with  pyinaturalist and what is the format to use for it?

jesse rorabaugh

unread,
Jan 20, 2019, 1:24:21 PM1/20/19
to iNaturalist
Interesting concept. I will have to play around with it a bit.

For submissions it is probably somewhat specialized in application. My usual routine is to photograph everything at a site I think someone might be able to identify. Some submissions have one photo, some twenty. The existing submission tool works pretty well for this paradigm and I am not sure a python script could make things much easier.

Python would work really well for someone trying to map every plant of a particular type on a plot, particularly if it can be confirmed from one photo. Take one photograph of each plant, geotag it, and put it in a folder with only photographs of that one species. Then write a script which submits each photo in a folder as a separate iNaturalist observation giving them all the same species name. While I haven't tried this, it seems like a couple days of pyinaturalist time could make this type of batch upload of thousands of observations into a simple task.

Can you get the iNaturalist photo identification algorithm result from python? if so, a similar script could be developed for anyone who submits observations of just one photo. Submit every single photo in a folder to iNaturalist with the identification of the top species in the submission algorithm. This would drive identifiers nuts, but in another couple of years the species identification will be so good that this will be credible.

jesse rorabaugh

unread,
Feb 3, 2019, 9:19:06 PM2/3/19
to iNaturalist
I decided to play a little with pyinaturalist. Made a script which allows this workflow:
  • Put a bunch of photos in a folder whose title starts with the taxon id. Each observation must be a single photo.
  • Run this script. It uploads every photo as an observation with the time and location from the photo.
Not sure it fits well in many people's workflow, but it might help others who want to make a script which matches what they do. If you happen to have a photo of a few hundred individuals of the same species this can very quickly post everything.

Reply all
Reply to author
Forward
0 new messages