"Working on the complexity that is always indirectly implied by simpilicity."

Amplify's TwitterN, Yet Another C# Twitter REST API Library

http://code.google.com/p/twittern

I put together a C# twitter library that uses WCF's DataContract & DataMembers and .Net 3.5's DataContractJsonSerializer.  Its currently in alpha stage, as I need to finish writing the tests, documentation and make a simple WPF client for twitter.  I needed a twitter library for a personal "secret" project of mine and found that most twitter libraries do not keep up with the twitter API and break when using them. Plus they tend to go to great lengths when parsing the xml.  Unfortunately I do not know if this will work on mono yet. It seems that they have "Olive", which is mono's version of WCF and I've seen where they have a path for the "DataContractJsonSerializer".  If there are any one familiar enough with mono, please by all means use the code, join the project. 

One design decision that I made was to use Json rather than xml as its more compact and less data to transfer.  I used WCF because with DataContract & DataMembers you can parse Json and you can name your properties the property way with Pascal Case properties and then tell wcf what attributes of json they represent. This way you don't have properties that look like ruby like "screen_name" or  "profile_sidebar_border_color" in your Data Transfer Object in order to deserialize the Json response from twitter.

 

A basic sample of how to use the library is below.


using Amplify.Twitter;
using System.Security;

// ... stuff

public void Test() 
{
	SecureString password = new SecureString();
	string temp = "password";
	for (var i = 0; i < temp.Length; i++)
		password.AppendChar(temp[i]);
	
	password.MakeReadOnly();
	Twitter.SetCredentials("Username", password);

	StatusService service = Twitter.CreateStatusService();
 	// or StatusService service = new StatusService("Username", password);

        List<Status> tweets = service.GetUserTimeline("MichaelHerndon");
}

Labels: , , , , , , ,

3 Comments:

Blogger msftguy said...

i keep getting a 401 from twitter when i call GetFriendsTimeline() but GetUserTimeline() works fine.

7/21/2008 11:18:00 PM  
Blogger michael herndon said...

i'll take a look at this later today after my shift. Thanks!

7/22/2008 06:40:00 AM  
Blogger michael herndon said...

if your using the Twitter.CreateStatusService, make sure you call


Twitter.SetCredentials("username", "password");


or

are you running the tests that come with it? if so, make sure the Username and password set in the AssemblyFixture.cs




public static readonly string Username = "Username";


[FixtureSetUp]
public void OnStartUp()
{

Twitter.SetCredentials(Username.ToLower(), "yourpassword");

AccountService service = Twitter.CreateAccountService();
service.Verify();
}



if those are not set, you will get a 401 unauthorized error because those urls required http basic authentication.

if this doesn't solve your problem, please let me know and send a code example of what your doing.

7/22/2008 07:32:00 AM  

Post a Comment

Links to this post:

Create a Link

<< Home