Wednesday, March 31, 2010

The Learning Ramp for the Twitter API:Search API

The Search API for twitter works by returning what you ask for. To use the search API use the URL in your program, or web browser (I recommend seeing it with the Firefox json viewer): There are actually 5 ways to use the Search API.

  • search
  • trends
  • trends/current
  • trends/daily
  • trends/weekly

Here is an example of how to use the search API. To see how all the others work see Twitter API documentation.
  • http://search.twitter.com/search.format
  • The formats are:
    • JSON
    • Atom
    • For example: http://search.twitter.com/search.json
    • For example: http://search.twitter.com/search.atom
There are a lot of parameters that let you see what type things you want to search for. I can give an example below for me searching for what Apigee tweets about. I will use the q parameter in this example, and use it search from  a user. The example will be in both formats as follows:
  • http://search.twitter.com/search.atom?q=from:apigee
  • http://search.twitter.com/search.json?q=from:apigee
You can place both URL's in your Firefox web browser with the json viewer, and they should both let you see my tweets only. You can also view them using cURL (cURL is a very versatile command line utility which is designed to script web pages interactions.) 

As you can see the Twitter search API is really very simple to use, and can easily be implemented into the app that you are building. Take this very simple python code that uses the twitter API. First you must download the twitter library for python. Here is the code:

import twitter //This is how you call the twitter library.

client = twitter.Api () //You can expose the twitter API with this class
latest_post = client.GetUserTimeline("apigee")// This makes sure the the twitter.API class will fetch Apigee recently posted public tweets.
print [s.text for s in latest_post]//This will print out only the text for Apigee posts.










Tuesday, March 30, 2010

Learning the Twitter API: Some Facts

Here some good facts to know about the Twitter API:
  • Twitter has 2 discrete REST API(s)
    • Search API - Allows developers methods to interact with Twitter Search and trends data.
    • REST API-Allows developers to access core Twitter data like updated timelines, status data, and user information
  • Twitter has 1 Streaming API
    • Streaming API- Provides developers with near real-time high-volume access to Tweets in sampled and filtered form.
  • The Twitter API is RESTful and it supports the following data formats.
    • XML
    • JSON
    • RSS
    • Atom
  • There is a rate limit imposed on all 3 types of APIs.
    • You can only have 150 API requests per hour for the REST API.
    • The Search API has a higher rate limit then 150 requests per hour.
    • The Streaming API has a rate limit appropriate for long lived connections.
  • The Twitter API is HTTP based
    • Methods that receive data from the Twitter API requires a GET request.
    • Methods that submit,change, or destroy data the Twitter API requires a POST request.

Monday, March 29, 2010

Learning Ramp for the Twitter API:Overview of the Twitter API

Twitter bases two of its APIs off the REST architecture so that way the service works better with different Web syndication formats. Twitter works with two Web syndication format known as RSS(Really Simple Syndication) and Atom(Atom Syndication Format), both are ways to receive data from one source and send it to another. Twitter allows third party developers partial access to its API, so people can can easily use Twitter's service in the application that they are building. Twitter has three different types of API's:

  • REST API
  • Search API
  • Streaming API
The REST API and the Search API are the two API's that are based off the REST architecture, while the Streaming API is based of another architecture. In my next few entries I will breakdown the 3 different types of twitter API's, and how they are used.

Learning Ramp for the Twitter API:Terminology

Part the the learning ramp for the twitter API is to make sure I understand all the terminology, and know how it works. Dealing with the twitter API there are a lot of terms that might be unknown to many first time developers, and it is important that everyone know the lingo. In this entry I will go through all the terms I am unfamiliar with and define/explain how they pertain to the twitter API in my own words.


  • API (Application Programming Interface) - To be clear here we are dealing with web API's and they work basically by allowing an interface for the software of two web programs to interact with each other on the back end, and make requests. An analogy could be that you are needing a ride from your Mom to you friend's house because you do not know how to drive, and you have to communicate that to her so she will be to give you a ride to your friend's house. Much like how the the Twitter API works if you have an app that finds only tweets about healthy eating tips you have to allow your app to interact with the Twitter API and ask it to give you only those tweets about healthy eating. 
  • REST (Representational State Transfer) - Is a software architecture that is used for the World Wide Web. REST works by a client requesting some form of information from a server, and that server returning the appropriate response. REST uses sources of specific information, which it calls resources. To alter the resource, servers communicate through a HTTP proxy and exchange representations of the resource. So in non-technical terms for example, I am the client and I want to eat an egg which is the resource, but I the egg (resource) can be represented in many ways such as scrambled,sunny side up, boiled or omelet style from the pan (server).
  • SOAP (Simple Object Access Protocol) - Is a specific protocol for the exchange of structured information in implementation of Web services, so it basically takes a message or API, converts it into machine readable XML format, and thus making that message easier for third party sites to use. 
  • XML ( eXtensible Markup Language) - Is a type of markup language, which converts documents into machine readable format. Basically if you typing some thing in English and sending it to someone who can only read and write in Chinese, by the time you send it the English text is converted into Chinese so the Chinese person can easily decipher the message. XML works in that same way it changes any message you send to your program to machine language so your computer can understand that message as well.
  • JSON (JavaScript Object Notation) -Is an alternative to XML, but works in the same way. It works by serializing and transmitting structured data between a server and a web application. The difference is that JSON is in human readable format, and it is only used for data exchange. It is primarily used in data exchange over the internet. JSON is also much less complex and smaller in size than XML thus making it lightweight, but both struggle with mechanisms for representing large binary data types like image data.
So what I learned from all of these terms is that REST is much more flexible in data exchange then SOAP, which is why I assume that twitter's API is RESTful. Also I learned that JSON is the preferred way to exchange data over the internet, because it is simpler and more lightweight then converting the data to XML. It makes sense why people don't like using SOAP! 

Friday, March 26, 2010

Things are much clearer

So today I had a great chat with Sam Ramji about learning the twitter API. I am gonna be taking a different approach to building this app and learning the twitter API inside and out. Me learning the twitter API and using our product Apigee for analytics will put me in good place to talk shop with twitter developers in the near future. So the first thing that I will be doing is posting everyday what knowledge I have gained about the twitter API. I also think it would be good for me to put my tasks for the Apigee team here as well:


  • Apigee adoption.
  • Write Customer Blogs.
  • Get Customer Insights.
  • Get Smart about the twitter API.
    • Understand the learning ramp and document it. 
    • Identify all the tools that I will use and need.
    • Catalog the issues people face with the twitter API and identify those problems with the most frequency. 
  • Identify the twitter API geniuses.
    • Cataloging the smartest developers.
    • Find 5 cool twitter apps a week and identify the developer.
This really gives me a good direction and defines my task clearly for the next couple of weeks.  

Tuesday, March 16, 2010

Getting Started with the Twitter API.

I will be building an application using the twitter API. I have decided to use the ruby language to code the twitter API with. The goal is to build an app that will show all tweets from Apigee, Mashery, and 3Scale on a daily basis. The first thing I must do is familiarize myself with the ruby language, and then start using Ruby on Rails for building the app. I have to download all the tools for Ruby and follow a tutorial, and once I understand the Ruby language I can move on to the Rails platform.  I found these two links useful in downloading all the tools I need to get started with Ruby!


Backend: XAMPP

Editor: Aptana RadRails

Also I will be using the sappiresteele ruby tutorial.