EventBrite and AgFx – Windows Phone development

So you will already know that anything linked to online data should be retrieved using AgFx! Now if you have that, let me show you how you can use this for retrieving event data from EventBrite ( an online service to host an event calendar and maintain attendees data ).

EventBrite is a cool online service that also comes packed with a great API that will allow devs to integrate it in their own apps.

Before I continue I must point out that there is also a clean .net wrapper available, called EventBrite.Net but like I stated above, I’m more hooked on AgFx so I didn’t used the wrapper.

Before you can do anything with the EventBrite API you first should get an API key through their website here… After that you are set to go! With that API key you can than start using all API methods that are described on the EventBrite API documentation here…

For this demo we will try to download a list of events for a given organizer, the API method to get this info is organizer_list_events. But before we can do anything in our program we need to have .net objects representing the EventBrite response. Getting this information is not that difficult… First find an organizer and get it’s ID. You’ll only need to get the list of all events given by the organizer and EventBrite will show you his ID in the URL: I used this one http://www.eventbrite.com/org/2276332563 so the ID here is 2276332563

With this, you can use Fiddler to take a look at the returning JSON result. Open the composer tab in Fiddler and paste a legal EventBrite API method URL in the GET input box: https://www.eventbrite.com/json/organizer_list_events?app_key=[YOUR KEY HERE]&id=2276332563
When everything is ok, you’ll get a big JSON result back that contains all event information. This result will help you getting the needed .net objects! In Fiddler open the Raw tab in the Response pane and only copy the JSON string… after you have copied that, use a word processing tool to strip it of all unneeded line returns ( ex: Notepad++ with TextFX plugin – Unwrap text ). With your currently stripped JSON response go to the fantastic site called json2csharp! Paste your JSON code and press the Generate button, when all goes well you’ll get following result:

Or you can just copy it from my blog post Winking smile

DO NOTE that not it seems that not all JSON names are .net compatible resulting in _invalid_name_ prefixes! My suggestion is to change the .net class and ‘manipulate’ the JSON mapping in your app! ( I’m NOT covering this in the rest of the example )

So you added these classes in some Model part of your project, next up hooking up AgFx to EventBrite. To get this working you’ll need to create an AgFx ‘viewmodel’, here is how I did it:

A lot of code, but if you are used to working with AgFx, most of it will look familiar… The only ‘special’ thing is being done inside the GetLoadRequest method, here we need to give AgFx our API method URL. So I just wrapped all possible methods inside a static class EventBriteAPI. But in the end all it does is generate the same URL we used in Fiddler being: https://www.eventbrite.com/json/organizer_list_events?app_key=[YOUR KEY HERE]&id=2276332563

So that’s it, now you will have all events retrieved from EventBrite through AgFx! Happy coding!

Tweetsharp and AgFx – Windows Phone 7

Being a big fan of AgFx for any online data retrieval, I was exited to see Bjorn Kuiper his blog post about using Tweetsharp together with AgFx in a WP7 app. You can read all about it here… it shows you how to display tweets from a specific users’ timeline.

But like many blog posts, most of the time you’ll have to tweak them to work in your own scenario. So also with this one, I needed to manipulate some code to get my case working. Best to start off, is downloading Bjorn’s example here.

What I wanted to achieve, was to show a list of tweets done by a Search, also through the use of Tweetsharp and AgFx of course. But what I soon found out was that the code of Bjorn uses the class TwitterStatus that contains a tweet, in my case the returning items are of type TwitterSearchStatus. They are actually not that different, but I ran into some serialization/deserializations issues.

So what was my problem… when you get your search results back from Tweetsharp you want to serialize them so that you can use the AgFx feature. In Bjorn’s example, he strips the Entities from the TwitterStatus before serializing. Found in the Execute method of the TwitterLoadRequest class.


But like I stated before I’m not working with TwitterStatus but with TwitterSearchStatus and it seems that performing the same action has no effect and I was still getting problems with the Entities property when Deserializing.

So how did I solve this, well I used Json.net from James Newton-King, also available as a NuGet here. So, instead of using the .Net DataContractJsonSerializer like Bjorn, we use the JsonConvert.SerializeObject. This gives us following code that replaces the one show above:

What you will notice is that I’m doing a special kind of Serialization… using a DynamicContractResolver! This is needed to manipulate the Json serialization, because if we don’t do anything, we’ll still have an output Json string containing the Entities properties.

So to fix this, you’ll need to interact when Json.Net tries to convert your class to Json, how to do this is is by creating your own class that inherits from DefaultContractResolver.


As you can see, Json.net finds properties to serialize, so he will pass the CreateProperties method, what we do here is use Linq to filter out the Entities, resulting in a total Json outpot string containing serialized TwitterSearchStatus objects without any Entities property.

The only thing left to do is Deserialize everything back in the Deserialize method of your AgFx DataLoader class.


So now you’ll be getting TwitterSearchStatus objects back from AgFx that you can use in your WP7 Views! Happy coding…