WP7: Tweetsharp and AgFx

UPDATE 2012/04/13: check out this great post of ‘Depechie’ about using TweetSharp and the TwitterSearchStatus object together with AgFx.

I like to add a Twitter feed to the “About” page in my Windows Phone apps. This way I can inform the users about the latest updates through my twitter account.

Why re-invent the wheel when you can use existing libraries? I used Tweetsharp and AgFx data caching library.

I use AgFx so I can display the previous retrieved (cached) Twitter feed while it’s loading the new one. A common concept you see in almost any ‘news’ app.

I would like to share my implementation (code) which also includes a small work-around to make TweetSharp work with AgFx.

I think the code is pretty much self-explanatory but here are some pointers:

Installing TweetSharp through NuGet

Execute the following command in your NuGet Package Manager Console:

Install-Package -IgnoreDependencies TweetSharp

This will make sure the library installs successfully. Installing it through the normal method won’t work because the Hammock library is not yet updated to Windows Phone 7.1 (Mango) and will cause a roll-back of your installation.

Add your own Twitter OAuth key

Update the fields ‘Consumerkey’ and ‘Consumersecret’ in the class TwitterLoadRequest (TwitterFeed.cs)

            private const string Consumerkey = "yourconsumerkey";
            private const string Consumersecret = "yourconsumersecret";

Extension of Tweetsharp library

When writing this code the TwitterEntity object of the TweetSharp library didn’t support serialization. Serialization is neccessary for it to work with AgFx. This is why I introduced the additional classes MyTwitterEntity and MyTwitterUrl.

Tweet.cs

Each separate tweet is loaded into this object.

AgFx supporting classes

The classes TwitterFeed, TwitterDataLoader and TwitterLoadContext are supporting classes for the AgFx framework. They make sure the data is loaded and automatically cached. The caching policy is defined through an attribute on the TwitterFeed class named “CachePolicy”. More information on this can be found on the AgFx website.

TweetStatusConverter

The TweetStatusConverter uses the TweetEntity information to highlight the URL’s in tweets and make them available als links that you can click. It uses the OpenWebBrowserCommand class to open a webbrowser when the link is clicked.

  1. Windows Phone 7: Tweetsharp and AgFx - pingback on 2012/03/21 at 7:37 am
  2. Great!!
    But when I run the project, “ArgumentException” always occurs on “InitializeComponent” of “App.g.i.cs” which was created by system tool automaticly.
    Anybody has the same problem? How can I fix it?
    Thanks!

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackbacks and Pingbacks: