Metro Nuggets

Bitesized tidbits for building Modern (Metro) apps.

Belatedly Introducing LiveSDKHelper

A while back I was working on a project that allowed me to actually look at, and use, the Live SDK in order to access information on SkyDrive. I was surprised to find just how hard it was to use the Live SDK, so as part of building the main project, I also built a little helper for using the Live SDK.

The Solution

So what is the LiveSDKHelper? Well basically, it’s a collection of classes, enums and strings that just take the chore out of using the Live SDK. It’s a portable class library that works with both Windows Phone (7.5 and 8) and Windows 8. But you probably assumed that, right!

Onto some code! In Windows Phone, as part of the Live SDK, we are given a signin button control that we can use to enable our end users to sign into their Microsoft Account. This button requires you to give it some scopes so the user knows exactly what information your app wants to access. This is the first part of the helper:

            //wl.basic wl.signin wl.offline_access wl.skydrive_update wl.calendars
            var scopes = new List

            SignInButton.Scopes = scopes.ToConcatenatedString(
                scope => scope.ToStringScope(),
                " ");

So no more remembering what each scope’s string was.

Within the library are a number of constants for you to use in order to access certain parts of the Live SDK, like your Skydrive root folder, or your photos folder, or to get your friends. For example:

var result = await _client.GetAsync(MeDetails.MyFriends);

This makes it really easy to make sure you’re putting the right strings into the client calls.

But what about the responses? Some of the posts I’ve seen create dynamic objects based on the results, but what if you want something a bit more concrete? Well in all the responses back from the client is a property called RawResult, which is basically a JSON object that can be deserialized with your favourite deserializer. What my library gives you is a set of concrete classes that you can use in order to deserialize those results. Again, some code:

        private async void HowManyFriends_OnClick(object sender, RoutedEventArgs e)
            if (_client == null) return;

            var result = await _client.GetAsync(MeDetails.MyFriends);
            var contacts = JsonConvert.DeserializeObject(result.RawResult);

            MessageBox.Show("You have " + contacts.Items.Count + " friends!!");

Again, this just makes it so much easier to deal with. And there’s plenty more to explore. At the moment, the library covers SkyDrive, Calenders and contacts.

If you want to give it a go, it’s installable from nuget.


The source for it is all on GitHub, and if you want to see an app using it, check out Store Card Buddy.


2 responses to “Belatedly Introducing LiveSDKHelper

  1. Pingback: Cross-Platform Portable Class Libraries with .NET are Happening - Scott Hanselman

  2. Pingback: .Net 跨平台可移植类库正在进行 - Scott Hanselman的中文博客 - Site Home - MSDN Blogs

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: