Getting Started with the Twitter API Console

In past columns we’ve looked at several different ways to use the Twitter API to search, post tweets and various other Twitter related functions. The console at is another useful way to access Twitter functionality. The console provides access to basically all of the API functions. It can be used to research functionality and Twitter data, debug issues in API calls for your own applications or even design calls for those apps. This powerful and easy to use tool is made by Apigee. They have a version posted on their own site along with an informative getting started video outlining the major features.

Let’s take a look at a quick example to see the current Twitter trends. Once you access the console, it may take a moment for the tool to load depending on your connection speed. Once it does you should see an interface similar to the one pictured above.

The left-hand menu lists available API calls (or functions) and the right, main column is reserved for the response of the queries. Search down to near the bottom of the function column for Trends. Open up the Trends parent category and select the first function also called trends. The top URL field will update to show the full URL to the Trends -> trends endpoint.

To the right of this URL click on the large orange button label GET to execute the trends call and update the results pane with the output.

The top section of the results is the HTTP protocol header. This data will vary depending on the usage and location. Similar headers are passed back and forth for every HTTP page, image and file accessed over the web.

Below the header is the result of our API query. Scroll down to see all of the result data. The result may not be immediately understandable as it is in a machine-readable format called JSON, but you should be able to pick out enough of the keywords to see what’s going on. Though the exact output will be different depending on what Twitter topics are actually trending when the query is executed, there should be several dozen lines starting like:

"trends": [
"name" : "#thatswhyursingle",
"url" : ""
"name" : "#ispendwaytomuchmoneyon",
"url" : ""
... snipped ...
"as_of" : "Mon, 16 May 2011 19:04:05 +0000"

Where name is the hashtag trend and url the full URL to search for this trending tag directly at Twitter. In PHP we can extract the JSON data into an array for usage with json_decode(). See for examples of using the JSON format in other programming languages.

For a more useful example of the console, let’s retrieve a user’s timeline. Back in the API console function list in the left-hand pane, click on Timeline then statuses/user_timeline. The console URL field will update to:<strong>{screen_name}</strong>

The user_timeline endpoint requires a screen_name as a parameter so the API knows which user’s timeline it is being asked for. Replace {screen_name} with the Twitter screen name of the desired user before submitting the query so that it looks like this:<strong>alltwtr</strong>

Execute the query in the console and the response will be similar to the previous example consisting of a header and the JSON reply data.

"retweet_count" : 1,
"in_reply_to_status_id" : null,
"text" : "CBS Cancels "$#*! My Dad Says"  Will We Ever See Another Twitter-Inspired Show?",
"created_at" : "Mon May 16 21:15:15 +0000 2011",
"in_reply_to_screen_name" : null,
"in_reply_to_status_id_str" : null,
"contributors" : null,
"retweeted" : false,
"in_reply_to_user_id_str" : null,
"source" : <a rel="nofollow" href="">HootSuite</a>,
"id_str" : "70235890852691968",
"place" : null,
"coordinates" : null,
"geo" : null,
"in_reply_to_user_id" : null,
"truncated" : false,
"user": {
"contributors_enabled" : false,
"notifications" : false,
"created_at" : "Fri Jan 22 19:16:39 +0000 2010",
"profile_sidebar_border_color" : "C0DEED",
"listed_count" : 295,
"following" : true,
"description" : "Community, news, and resources from - the unofficial twitter resource",
"statuses_count" : 1413,
... snipped ...
"id" : 70235890852691970,
"favorited" : false
... snipped ...

Recommended articles