<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>C#, VB.Net, XML and mass consumption of coffee. &#187; Twitter API C#</title>
	<atom:link href="http://www.paul-zubkov.com/tag/twitter-api-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.paul-zubkov.com</link>
	<description></description>
	<lastBuildDate>Wed, 03 Feb 2010 18:25:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Twitter API with C# example(part 2)</title>
		<link>http://www.paul-zubkov.com/2009/08/02/twitter-api-with-c-examplepart-2/</link>
		<comments>http://www.paul-zubkov.com/2009/08/02/twitter-api-with-c-examplepart-2/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 07:11:23 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[Twitter API C#]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.paul-zubkov.com/?p=249</guid>
		<description><![CDATA[
First of all, I have to admit that I decided to take a vacation.  Vacation from everything &#8211; work, freelance, projects, blog, etc.  It&#8217;s summer and despite the crappy weather here in Toronto, I am spending time with my family which actually rocks.  Now vacation is over, let&#8217;s get back to coding [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-254" title="sundial" src="http://www.paul-zubkov.com/wp-content/uploads/2009/08/sundial.jpg" alt="sundial" width="300" height="225" /></p>
<p>First of all, I have to admit that I decided to take a vacation.  Vacation from everything &#8211; work, freelance, projects, blog, etc.  It&#8217;s summer and despite the crappy weather here in Toronto, I am spending time with my family which actually rocks.  Now vacation is over, let&#8217;s get back to coding &#8211; today I wanted to continue with Twitter examples.  Twitter seems to be very hot, and I was curious as to how to get the most out of it from the coding perspective.    Here is a tiny function that gets the followers of a user, providing we know the username and password:</p>
<p><code lang="csharp[lines]">public string FetchFollowers(string userName, string password)<br />
{<br />
    using (var client = new WebClient())<br />
    {<br />
        client.Credentials = new NetworkCredential(userName, password);<br />
        try<br />
        {<br />
            using (var stream = client.OpenRead("http://twitter.com/statuses/followers.xml"))<br />
            {<br />
                using (var reader = new StreamReader(stream))<br />
                {<br />
                    return reader.ReadToEnd();<br />
                }<br />
            }<br />
        }<br />
        catch (WebException ex)<br />
        {<br />
            //insert code to deal with exception HERE<br />
        }<br />
    }<br />
    return string.Empty;<br />
}</code></p>
<p>There are two types of &#8220;connection&#8221; between the people on twitter &#8211; followers and friends &#8211; I am too lazy to look up the difference between the two, but if you want list of friends then line 8 in the function above should look like this:</p>
<p><code lang="csharp[lines]">using (var stream = client.OpenRead("http://twitter.com/statuses/friends.xml"));</code></p>
<p>I usually stuff the output of that in XML and then do what I need to do with it.</p>
<p>Let me take a break for now, next time we will cover posting to Twitter (status update).</p>
<p>BTW, first part of this could be found <a href="http://www.paul-zubkov.com/2009/07/01/twitter-api-with-c-examplepart-1/">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.paul-zubkov.com/2009/08/02/twitter-api-with-c-examplepart-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter API with C# example(part 1)</title>
		<link>http://www.paul-zubkov.com/2009/07/01/twitter-api-with-c-examplepart-1/</link>
		<comments>http://www.paul-zubkov.com/2009/07/01/twitter-api-with-c-examplepart-1/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 02:21:48 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[Twitter API C#]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.paul-zubkov.com/?p=220</guid>
		<description><![CDATA[
Currently I am involved in a project where number of things have to be done using Twitter API.  What really amazes me today is the quality of API&#8217;s available to developers.  Twitter is a perfect example of such API.  I will try to publish some code that I used to accomplish several [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.paul-zubkov.com/wp-content/uploads/2009/07/sunflower.jpg" alt="sunflower" title="sunflower" width="299" height="200" class="alignnone size-full wp-image-229" /></p>
<p>Currently I am involved in a project where number of things have to be done using Twitter API.  What really amazes me today is the quality of API&#8217;s available to developers.  Twitter is a perfect example of such API.  I will try to publish some code that I used to accomplish several tasks starting with getting the details of a Twitter user providing you are aware of the user password and username.</p>
<p>Following code will retrieve a variety of information about a Twitter account:<br />
<code lang="csharp"><br />
public string FetchUserDetailsAsXml(string userName, string password, string IDorScreenName)<br />
{</p>
<p>        if(string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))<br />
        {<br />
            throw new ArgumentException("userName or Password are not supplied, that is not good.");<br />
        }</p>
<p>    string url = string.Format(TwitterBaseUrlFormat, "users", "show" + "/" + IDorScreenName, "xml");</p>
<p>    using (var client = new WebClient())<br />
    {<br />
        client.Credentials = new NetworkCredential(userName, password);</p>
<p>        try<br />
        {<br />
            using (var stream = client.OpenRead(url))<br />
            {<br />
                using (var reader = new StreamReader(stream))<br />
                {<br />
                    return reader.ReadToEnd();<br />
                }<br />
            }<br />
        }<br />
        catch (WebException weex)<br />
        {<br />
            if (weex.Response is HttpWebResponse)<br />
            {<br />
                if ((weex.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotFound)<br />
                {<br />
                    return null;<br />
                }<br />
            }<br />
            throw;<br />
        }<br />
    }</p>
<p> }<br />
</code></p>
<p>That&#8217;s pretty much it.  Need System.Net and System.Web for this, obviously.  What you get out of that looks like this:</p>
<p><code lang="xml"></p>
<p>- <user><br />
  <id>14381487</id><br />
  <name>pzubkov</name><br />
  <screen_name>pzubkov</screen_name><br />
  <location>Ontario, Canada</location><br />
  <description>Coder, mostly .net</description></p>
<profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/56116140/Me_normal.jpg</profile_image_url>
  <url>http://www.paul-zubkov.com</url></p>
<protected>false</protected>
  <followers_count>39</followers_count></p>
<profile_background_color>709397</profile_background_color>
<profile_text_color>333333</profile_text_color>
<profile_link_color>FF3300</profile_link_color>
<profile_sidebar_fill_color>A0C5C7</profile_sidebar_fill_color>
<profile_sidebar_border_color>86A4A6</profile_sidebar_border_color>
  <friends_count>61</friends_count><br />
  <created_at>Mon Apr 14 05:08:22 +0000 2008</created_at><br />
  <favourites_count>0</favourites_count><br />
  <utc_offset>-18000</utc_offset><br />
  <time_zone>Eastern Time (US  Canada)</time_zone></p>
<profile_background_image_url>http://static.twitter.com/images/themes/theme6/bg.gif</profile_background_image_url>
<profile_background_tile>false</profile_background_tile>
  <statuses_count>49</statuses_count><br />
  <notifications>false</notifications><br />
  <verified>false</verified><br />
  <following>false</following><br />
- <status><br />
  <created_at>Wed Jul 01 19:15:11 +0000 2009</created_at><br />
  <id>2424620582</id><br />
  <text>twitter api rocks, this is sweet</text><br />
  <source></source>web</p>
<truncated>false</truncated>
  <in_reply_to_status_id><br />
  <in_reply_to_user_id><br />
  <favorited>false</favorited><br />
  <in_reply_to_screen_name><br />
  </in_reply_to_screen_name><br />
  </in_reply_to_user_id><br />
</in_reply_to_status_id></status></user></code></p>
<p>As we can see from above, I am not an avid Twitter user myself, but I find that the API produced by Twitter is extremely well done.  In Part 2 and 3 I will cover sending new update and getting followers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paul-zubkov.com/2009/07/01/twitter-api-with-c-examplepart-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
