First things first: before starting, you need to learn some basics from Twitter app development. If you are already familiar with these principles, you can move forward to the “Hello Twitter” app example.
1. Twitter REST api
Twitter has different api’s, for different purposes. We will be working with the REST api, which is the right option if you want to make an app to read and write data. From the Twitter documentation, some explanation about the REST API:
[box type="info"] The REST API enables developers to access some of the core primitives of Twitter including timelines, status updates, and user information. If you’re building application that leverages core Twitter objects, then this is the API for you. Imagine building a profile of a user: their name, their Twitter handle, their profile avatar, and the graph of people that they are following on Twitter – all with a few RESTful API calls. In addition to offering programmatic access to the timeline, status, and user objects, this API also enables developers a multitude of integration opportunities to interact with Twitter. Through the REST API, the user can create and post tweets back to Twitter, reply to tweets, favorite certain tweets, retweet other tweets, and more.[/box]
2. API calls
Everytime you request some data from Twitter API, you are making a call. There are call limits per hour, so we have to keep that in mind when designing our app. Here are the limitations:
- Unauthenticated calls are permitted 150 requests per hour. Unauthenticated calls are measured against the public facing IP of the server or device making the request.
- OAuth calls are permitted 350 requests per hour and are measured against the oauth_token used in the request.
Most of the time (unless you are using only search data) you will be working with authenticated calls. It seems a lot (350 per hour per user), but when we talk about applications that deal with a large amount of data (like TweetAuditor, requesting user followers from a user with thounsands of followers) its not that much. Never forget about these limitations! To learn more, check Twitter documentation about rate limiting: https://dev.twitter.com/docs/rate-limiting
3. Keys and Tokens
The Twitter auth schema uses 3 pairs of keys: one pair from the app; one pair for requesting the auth link; one pair from the user). With Twittertools, you just need to worry about the application keys - consumer_key and consumer_secret. These two keys are obtained when you register a Twitter app.
If you plan to make calls from a user that is not logged in (such as posting automatic tweets, for example) you will need to store the user keys – access_token and access_token_secret – somewhere (in a database table, most often). Be careful with these user keys, they must be kept safe. If your application doesn’t need to make unlogged actions, you don’t need to store the user keys – you don’t even need to know they exist.
4. Robot Apps x Multi-user Apps
There are two main twitter application types, as explained below:
Robot Apps – single-user app that doesn’t need to authenticate users. Its the simplest app you can write. In this case, all actions performed by the app will be executed by the same twitter user. In this case, you need to have the access_token and access_token_secret from that specified user. If this user is the same who registered the app on Twitter (like, YOU), he just need to access the application settings to obtain his keys.
Multi-user Apps – in most cases, you will be dealing with multiple users, who need to be authenticated on your application, so you can make requests to the Twitter API to get the user’s timeline, followers, publish status updates or anything else. In this case, you will need that “Login with Twitter” button, so users can click on the auth link to authorize your app. After that, you are ready to collect user data and make any request – the Twittertools object will take care of the user access keys.
5. Lets Begin!
Now that you are familiar with these concepts, we can go ahead and make our first Twitter app: “Hello, Twitter!”
