Tag Archives: RestSharp

Uncategorized

Basic Facebook integration for your Windows Phone 7 application

Windows phone topic Facebook is unavoidable social engagement tool. If you are building a Windows Phone 7 application for a certain event, celebrity or anything that has a associated Facebook page, you should consider adding some sort of engagement with it in the app. One example is adding the most recent posts in some format to your client application. However, you cannot simply retrieve data from Facebook publicly, calls need to be authenticated first and for that we need to create a Facebook application first.

This post will show how to fetch the most recent posts from the page using only RestSharp. If you are building something more complicated with more integration, consider using this awesome library – Facebook C# SDK.

You can do that on the Facebook developers/Apps page and click Create New App and give your application a name. For the testing purposes, use some random app name. Creating new Facebook application read more »

Uncategorized

Async and RestSharp for Windows Phone 7

Windows phone topic I have mentioned RestSharp quite a lot of times, it is simply an essential library for building applications that communicate to the outside world. Ever since Async CTP shipped for Windows Phone 7, I wanted to make everything asynchronous. RestSharp comes with asynchronous methods already built in, but they are not compatible with Async since they don’t return Task.

But we can fix that easily with our good friend TaskCompletionSource<T> read more »

Uncategorized

Deserializing POC objects from strings using RestSharp deserializators

Windows phone topic RestSharp is a wonderful little library for communicating with REST services. There is one thing I like in particular – their forgiving deserialization classes. They are awesome, but they cannot deserialize plain strings. If you take a closer look at the Deserialize methods, you will notice that they accept an object of the class that implements IRestResponse. If you inspect the source code (it is open source over at github), you will see that only Content property is used.

So, let’s implement our FakeResponse class that will wrap our string:

public class FakeResponse : IRestResponse
{
    public string Content { get; set; }

    // default implementation is OK
}

You can now deserialize it with the following snippet (xml holds the XML text read from some source other than web response):

var xmlDeserializer = new RestSharp.Deserializers.XmlDeserializer();
var rss = xmlDeserializer.Deserialize<Data.Rss>(new FakeResponse() { Content = xml });
Uncategorized

Error using the most recent version of RestSharp in wp7.

When adding RestSharp via NuGet to WP7 project, you will probably receive the following error:

File or assembly name ‘Newtonsoft.Json, Version=4.0.5.0, Culture=neutral, PublicKeyToken=30AD4FE6B2A6AEED’, or one of its dependencies, was not found.

read more »

Uncategorized

Google Data API with RestSharp on WP7 Update

Special thanks to John Sheenan who pointed out an error in my code. First of all, calling Dispatcher.BeginInvoke is redundant since the callback action will be invoked on the main thread.

Secondly, there is a powerful deserialization feature in RestSharp. Create a simple class that will correspond to the deserialized JSON object: read more »

Uncategorized

Google Data API with RestSharp on WP7

RestSharp is an open source REST client for .NET. I will use it for consuming Google Data API. You can easily install via the following NuGet command

Install-Package RestSharp

First step is creating an application in API Console and selecting services that you will be using. In this example, we will use the Tasks API. Once you create your project with the appropriate settings, you will need client_id and client_secret which is available on the API Access page. read more »