How to integrate Twitter data into your applications

Today I’ll explain how you can easily obtain data from Twitter and use it in your applications by using the Twitter REST API.

This API enables developers to access some of the core functionalities of Twitter, including timelines, status updates, and user information.

How to retrieve information

First you have to send a request by using the correct API resource URL and corresponding parameters. You have to specify the desired response format. The available formats are JSON, XML, RSS and ATOM. These formats can be chosen depending on your preferences.

http://api.twitter.com/1/{resource}.{format}?{parameters}

Example:
http://api.twitter.com/1/users/show.xml?screen_name=nclsptrs

string API = "http://api.twitter.com/1/users/show.xml?screen_name=nclsptrs";

XmlDocument xml = new XmlDocument();
xml.Load(API);

XmlNode user = xml.SelectSingleNode("user");
string Id = user.SelectSingleNode("id").InnerXml;
string Name = user.SelectSingleNode("name").InnerXml;
string Description = user.SelectSingleNode("description").InnerXml;
string Url = user.SelectSingleNode("url").InnerXml; 

Console.WriteLine(string.Format("User Info:\n{0} - {1}\n{2}\n{3}", Id, Name, Description, Url));

This application will retrieve the user information of a given user by his screen name.
The response will be in XML and needs to be parsed to get the values of the desired nodes.

Try out the API

Before using the API in your applications, you can experiment and explore it here:
https://dev.twitter.com/console

Note:
The API has a requests limit of 150 calls per hour for unauthenticated calls.
When you exceed the limit, you’ll get an error message: “Rate limit exceeded. Clients may not make more than 150 requests per hour”. OAuth calls are limited to 350 requests per hour based on the oauth_token used in the request.

Advertisements

Comments are closed.

%d bloggers like this: