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.
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.
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.
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.