Connect Live SDK in Windows Store Application


This article helps you to learn how to connect using Live SDK in a Metro style application. Metro style applications can freely communicate with Live SDK to achieve a single sign-on using a Microsoft account. Metro style applications can connect using Live SDK, JavaScript and managed programing languages like C# and Visual Basic.

Connecting using Live SDK in a Metro style application is very easy. Let's use the following steps to do this.

Step 1 : Install Live SDK

Step 2 : Add a Live SDK reference to the Metro style application

This article assumes you are already familiar with creation of Metro style applications. Create a Metro style application in Visual Studio and add the Live SDK reference from the Solution Explorer.


Step 3 :
Register your Metro style application in the Windows Live Dashboard. Click here to learn how to register a Metro style application on the Live Dashboard.

Step 4 : Copy the package name from the Live Dashboard and open the Package.appxmanifest file from your application and move to the packaging tab and paste the package name into the package name textbox.


Step 5 : Add the following two namespaces to your project:

using Microsoft.Live;
using Microsoft.Live.Controls;

Now we need to add a live connect Sign-in control from the Live SDK. In order to use the Sign-in control we need to add the following line of code to the MainPage.xaml file in your application:

  <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <live:SignInButton x:Name="btnSignin"   Scopes="wl.signin
 SessionChanged="btnSignin_SessionChanged_2" />

Remember : It is not compulsory to use a live connect Sign-in control; you can also use a button to connect using the Live SDK.

Step 6 : Add the following Live connection code to the MainPage.xaml file:

LiveAuthClient liveAuthClient;
     LiveLoginResult liveLoginResult;
     liveAuthClient = 
new LiveAuthClient("{please add your redirect url here}");
     liveLoginResult = 
await liveAuthClient.LoginAsync(new string[] { "wl.signin","wl.basic" });
if (liveLoginResult.Session != null && liveLoginResult.Status ==LiveConnectSessionStatus.Connected)
LiveConnectClient client = new LiveConnectClient(liveLoginResult.Session);
        LiveOperationResult operationResult = await client.GetAsync("me");
dynamic results = operationResult.Result;
        lblWelcome.Text = 
"Welcome " +;
        btnSignin.Content = 
"Sign out"
       throw new Exception();
catch (Exception ex)
      lblWelcome.Text = ex.Message;

Step 7 : Press F5 to run your project.


Enter your live credentials and click on sign in:


Click on yes and continue.

If you receive the following error it means you have not added the package name. Add it and run the apps again.


Remember : If you are using my project attached to this article then please add your Redirect URL to run the project smoothly. Also add your package name in the Package.appxmanifest file.

Thanks for spending your valuable time to read this article.


Similar Articles