Live SDK - Try to Sign In without SignInButton

后端 未结 3 2139
南笙
南笙 2021-02-05 13:02

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 t

3条回答
  •  醉话见心
    2021-02-05 13:51

    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!");
            }
        }
    }
    

提交回复
热议问题