Live SDK-尝试不使用SignInButton登录 [英] Live SDK - Try to Sign In without SignInButton

查看:79
本文介绍了Live SDK-尝试不使用SignInButton登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过任何方式登录Live for App(Silverlight,WP7均可)而无需单击登录"按钮.

Is there any way to login to Live for an App (Silverlight, WP7 can) without having to click on SignIn button.

例如,我想动态登录我:启动应用程序时,我要登录.如何在不使用按钮的情况下执行此操作?

I want to log me dynamically, for example: when you start the app, I want to log in to me. How to do this without resorting to the button?

推荐答案

我想出了办法,所以我决定分享:

I figured out how to do, so I decided to share:

using System.Windows;
using Microsoft.Live;

public class LiveLogin
{

    private static readonly string[] scopes = 
        new string[] { 
            "wl.signin", 
            "wl.basic", 
            "wl.calendars", 
            "wl.calendars_update", 
            "wl.contacts_calendars", 
            "wl.events_create" };

    private LiveAuthClient authClient;
    private LiveConnectClient liveClient;


    public LiveLogin()
    {
        this.authClient = new LiveAuthClient("**your client id here**");
        this.authClient.InitializeCompleted += authClient_InitializeCompleted;
        this.authClient.InitializeAsync(scopes);
    }

    private void authClient_InitializeCompleted(object sender, LoginCompletedEventArgs e)
    {
        if (e.Status == LiveConnectSessionStatus.Connected)
        {
            this.liveClient = new LiveConnectClient(e.Session);
        }
        else
        {
            this.authClient.LoginCompleted += authClient_LoginCompleted;
            this.authClient.LoginAsync(scopes);
        }
    }

    private void authClient_LoginCompleted(object sender, LoginCompletedEventArgs e)
    {
        if (e.Status == LiveConnectSessionStatus.Connected)
        {
            this.liveClient = new LiveConnectClient(e.Session);
            MessageBox.Show("Signed");
        }
        else
        {
            MessageBox.Show("Failed!");
        }
    }
}

这篇关于Live SDK-尝试不使用SignInButton登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆