Live SDK - Try to Sign In without SignInButton

后端 未结 3 2136
南笙
南笙 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:58

    Great answer Richard. This really helped a lot.

    I noticed a couple of comments from people complaining that they couldn't find the InitializedCompleted event. If you're coding in .Net 4.5 then you need to follow the async/await pattern for asynchronous methods. The class above would look like this:

    public class LiveLogin
        {
            private static readonly string[] Scopes =
                new[]
                    {
                        "wl.signin",
                        "wl.basic",
                        "wl.calendars",
                        "wl.calendars_update",
                        "wl.contacts_calendars",
                        "wl.events_create"
                    };
    
            private LiveAuthClient _authClient;
    
    
    
            public async Task Login()
            {
                _authClient = new LiveAuthClient("**your client id here**");
    
                LiveLoginResult result = await _authClient.InitializeAsync(Scopes);
                if (result.Status == LiveConnectSessionStatus.Connected)
                {
                    return new LiveConnectClient(result.Session);
                }
                result = await _authClient.LoginAsync(Scopes);
                if (result.Status == LiveConnectSessionStatus.Connected)
                {
                    return new LiveConnectClient(result.Session);
                }
                return null;
            }
    
    
        }
    

    MS have an async await primer here

提交回复
热议问题