After some playing around with WCF and Flickr, I decided to move everything internally for the twitter library to use WCF with it's ServiceContract. It was more of a pain that initially thought it would be. WCF is amazingly customizable but still has a couple of downfalls thanks to REST and people not writing their API for all technologies.
The biggest issue is that Twitter throws an Http 403 unknown exception when you call a page and something is incorrect in the url. Well with WCF, it throws a System.ServiceModel.Security.MessageSecurityException, due to the url returning a status code other than 200, and it wraps the inner exceptions inside of that.
I'm sure there is a better way to get around this, but each proxy call is now wrapped by a try/catch in the client class methods in order to check for the MessageSecurityException, then it checks the inner exception and determines if twitter sent back a response error message. If it does the library now throws a twitter exception with error information, otherwise you would only see the WCF exception that would mask the real issue.
Also I renamed the "Service" classes to "Client" seeing that is the proper term for them. The tests are now updated as well to reflect the changes. The tests are a good way of seeing of how to use the library. Last but not least, methods now return arrays instead of lists in order to be more REST friendly.
using Amplify.Twitter;
using System.Security;
// ... stuff
public void Test()
{
try {
string temp = "password";
Twitter.SetCredentials("Username", temp);
StatusClient client = Twitter.CreateStatusClient();
// or StatusClient client = new StatusClient("Username", temp);
Status[] tweets = service.GetUserTimeline();
} catch (TwitterException ex) {
Log.Write(ex.ToString()); // write the twitter rest error.
}
} Labels: Amplify, BHAG, C#, Code, CSharp, JSON, REST, Twitter, WCF
2 Comments:
i would love to see more examples of using the library. do you have an example of using the IUserClient interface?
thanks!
use cases or just the general concept?
Post a Comment
Links to this post:
Create a Link
<< Home