我正在开发一个Windows应用程序8.1(XAML / C#)与MVVM光。
我曾将我的LiveID里面的代码只是为了调试,但现在是时候做登录。
目前我只能和这一段代码:
this.authClient = new LiveAuthClient();
LiveLoginResult loginResult = await this.authClient.InitializeAsync(scopes);
它不断给我的错误:
类型“System.NullReferenceException”的异常出现在mscorlib.dll,但在用户代码中没有处理
附加信息:对象没有设置为一个对象的一个实例。
源代码:
private static readonly string[] scopes =
new string[] {
"wl.signin",
"wl.basic",
"wl.offline_access"};
private LiveAuthClient authClient;
private LiveConnectClient liveClient;
public DashboardView()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
this.InitializePage();
}
private async void InitializePage()
{
this.authClient = new LiveAuthClient();
LiveLoginResult loginResult = await this.authClient.InitializeAsync(scopes);
if (loginResult.Status == LiveConnectSessionStatus.Connected)
{
if (this.authClient.CanLogout)
{
this.btnLogin.Content = "Sign Out";
}
else
{
this.btnLogin.Visibility = Visibility.Collapsed;
}
this.liveClient = new LiveConnectClient(loginResult.Session);
this.GetMe();
}
}
private async void btnLogin_Click(object sender, RoutedEventArgs e)
{
if (this.btnLogin.Content.ToString() == "Sign In")
{
LiveLoginResult loginResult = await this.authClient.LoginAsync(scopes);
if (loginResult.Status == LiveConnectSessionStatus.Connected)
{
if (this.authClient.CanLogout)
{
this.btnLogin.Content = "Sign Out";
}
else
{
this.btnLogin.Visibility = Visibility.Collapsed;
}
this.liveClient = new LiveConnectClient(loginResult.Session);
this.GetMe();
}
}
else
{
this.authClient.Logout();
this.btnLogin.Content = "Sign In";
}
}
private async void GetMe()
{
Task<LiveOperationResult> task = this.liveClient.GetAsync("me");
var result = await task;
dynamic profile = result.Result;
}
我甚至尝试了一些不同的范围,这是我的最后一次尝试。
提前致谢。