Skip to content

Instantly share code, notes, and snippets.

@eternaltung
Created February 7, 2014 04:11
Show Gist options
  • Save eternaltung/8857280 to your computer and use it in GitHub Desktop.
Save eternaltung/8857280 to your computer and use it in GitHub Desktop.
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Microsoft.Live;
using Windows.UI.Popups;
namespace LiveSDKSample
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private async void LoginButton_Click(object sender, RoutedEventArgs e)
{
try
{
LiveAuthClient auth = new LiveAuthClient();
//要求自動登入與讀取基本資訊兩種權限
LiveLoginResult loginresult = await auth.LoginAsync(new string[]
{
"wl.signin",
"wl.basic"
});
if (loginresult.Status == LiveConnectSessionStatus.Connected)
{
LiveConnectClient liveClient = new LiveConnectClient(loginresult.Session);
LiveOperationResult operationresult = await liveClient.GetAsync("me");
//顯示登入帳號的姓名
MessageDialog msg = new MessageDialog(string.Format("Name:{0}",
operationresult.Result["name"]
));
await msg.ShowAsync();
}
}
catch (LiveAuthException ex)
{
MessageDialog msg = new MessageDialog(ex.Message);
msg.ShowAsync();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment