Access Twitter API using C#
Posted On Tuesday, June 2, 2009 at at 12:17 PM by test
There are various APIs or Wrapper libraries available on the following links
C# .NET Libraries for accessing twitter
static void Main(string[] args)
{
TwitterHelper objTH = new TwitterHelper();
objTH.DataFormat = "xml";
objTH.TwitterUrl = "http://twitter.com/statuses/friends";
objTH.TwitterUser= "UserNaME";
objTH.TwitterPass = "PASSWORD";
string xmlData = objTH.getTwitterMessage();
Console.WriteLine(xmlData);
Console.ReadLine();
}
}
Twitter Helper Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Net;
using System.IO;
namespace TwitterNameSpace
{
class TwitterHelper
{
///
/// Please Set TwitterURL without the dataFormat extension
///
public string TwitterUrl { get; set; }
public string TwitterUser { get; set; }
public string TwitterPass { get; set; }
public string DataFormat { get; set; }
public string getTwitterMessage()
{
try
{
System.Net.ServicePointManager.Expect100Continue = false;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(this.TwitterUrl+"."+this.DataFormat);
SetRequestParams(request);
request.Credentials = new NetworkCredential(this.TwitterUser, this.TwitterPass);
WebResponse response = request.GetResponse();
string content;
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(responseStream))
{
content = reader.ReadToEnd();
}
}
return content;
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
return null;
}
private static void SetRequestParams(HttpWebRequest request)
{
request.Timeout = 500000;
request.Method = "GET";
}
}
}
Happy Coding
Please feel free to ask if you face any problem
C# .NET Libraries for accessing twitter
static void Main(string[] args)
{
TwitterHelper objTH = new TwitterHelper();
objTH.DataFormat = "xml";
objTH.TwitterUrl = "http://twitter.com/statuses/friends";
objTH.TwitterUser= "UserNaME";
objTH.TwitterPass = "PASSWORD";
string xmlData = objTH.getTwitterMessage();
Console.WriteLine(xmlData);
Console.ReadLine();
}
}
Twitter Helper Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Net;
using System.IO;
namespace TwitterNameSpace
{
class TwitterHelper
{
///
/// Please Set TwitterURL without the dataFormat extension
///
public string TwitterUrl { get; set; }
public string TwitterUser { get; set; }
public string TwitterPass { get; set; }
public string DataFormat { get; set; }
public string getTwitterMessage()
{
try
{
System.Net.ServicePointManager.Expect100Continue = false;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(this.TwitterUrl+"."+this.DataFormat);
SetRequestParams(request);
request.Credentials = new NetworkCredential(this.TwitterUser, this.TwitterPass);
WebResponse response = request.GetResponse();
string content;
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(responseStream))
{
content = reader.ReadToEnd();
}
}
return content;
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
return null;
}
private static void SetRequestParams(HttpWebRequest request)
{
request.Timeout = 500000;
request.Method = "GET";
}
}
}
Happy Coding
Please feel free to ask if you face any problem