APIs for New Coders (Django + Bootstrap + Twython)
In a previous post I detailed how I wanted to learn how to connect to Facebook using a small Django project. My thinking is that just about any web application these days has to connect in some way to the major platforms online (Twitter, Facebook, LinkedIn, Pinterest, etc.) and just about any ambitious coding project you want to take on in the future needs to connect to a payments provider (Stripe, Braintree, etc.) if you're ever planning on making money from it.
And outside of the social + payments world, there are so many fantastic services available go developers now for email to photo sharing to anything else you can imagine, you're going to have to learn how to hook up your project to someone else's API.
For the complete beginners, the best definition I can give you comes from Wikipedia:
The practice of publishing APIs has allowed web communities to create an open architecture for sharing content and data between communities and applications. In this way, content that is created in one place can be dynamically posted and updated in multiple locations on the web.
Essentially, if an online service has an API you can connect your application to it and make use of the content / user profiles on the service.
Although I first started out thinking I'd dive into the Facebook API, since we use the Twitter API extensively at work, I figured if I ran into some issues like I usually do I could easily find out the answer.
After a bunch of research where I looked at various Django apps like Django-Social-Auth and Tweepy I decided to go with Twython because I could best understand how the code actually worked and how I wanted to use it.
To get started I copied a Django skeleton with Bootstrap that I have saved locally. I then copied the example models.py, views.py, urls.py and tweets.html from the incredibly useful example file that Twython creator Ryan McGrath put together.
The only hangup at that point was that I needed to go and change the app name (since I didn't clone the app directly) in the three files to the app name I had created for the project and I was good to go. /Login sent me to authenticate my Twitter credentials and /user-timeline prints out a list of tweets.
I'm going to dig further into the project I'm working on and my changes will be up on GitHub but I'm pretty damned pleased I managed to connect an app to the Twitter API.
If you're interested in what I get up to during the day check out www.getelevate.com.