private async Task LogIn(string permissions = null)
        {
            try
            {
                this.SessionStateChanged.RaiseEvent(this, new SessionStateChangedEventArgs(FacebookSessionState.Opening));

                // TODO: using Permissions for the time being until we decide how
                // to handle separate ReadPermissions and PublishPermissions
                var session = await this.facebookSessionClient.LoginAsync(permissions ?? this.Permissions);

                // initialize current session
                this.CurrentSession = session;
                this.SessionStateChanged.RaiseEvent(this, new SessionStateChangedEventArgs(FacebookSessionState.Opened));

                // retrieve information about the current user
                if (this.FetchUserInfo)
                {
                    FacebookClient client = new FacebookClient(session.AccessToken);

                    dynamic result = await client.GetTaskAsync("me");

                    this.CurrentUser = new GraphUser(result);
                    var userInfo = new UserInfoChangedEventArgs(this.CurrentUser);
                    this.UserInfoChanged.RaiseEvent(this, userInfo);
                }
            }
            catch (ArgumentNullException error)
            {
                // TODO: remove when bug in SDK is fixed (the bug happens when you cancel the facebook login dialog)
                var authenticationErrorEventArgs =
                    new AuthenticationErrorEventArgs("Login failure.", error.Message);

                this.AuthenticationError.RaiseEvent(this, authenticationErrorEventArgs);
            }
            catch (InvalidOperationException error)
            {
                // TODO: need to obtain richer information than a generic InvalidOperationException
                var authenticationErrorEventArgs =
                    new AuthenticationErrorEventArgs("Login failure.", error.Message);

                this.AuthenticationError.RaiseEvent(this, authenticationErrorEventArgs);
            }
            catch (FacebookOAuthException error)
            {
                var authenticationErrorEventArgs =
                    new AuthenticationErrorEventArgs("Login failure.", error.Message);

                this.AuthenticationError.RaiseEvent(this, authenticationErrorEventArgs);
            }
        }
示例#2
0
 private void OnUserInfoChanged(object sender, Facebook.Client.Controls.UserInfoChangedEventArgs e)
 {
     this.userInfo.DataContext = e.User;
 }
        private async Task LogIn(string permissions = null)
        {
            try
            {
                this.SessionStateChanged.RaiseEvent(this, new SessionStateChangedEventArgs(FacebookSessionState.Opening));

                // TODO: using Permissions for the time being until we decide how 
                // to handle separate ReadPermissions and PublishPermissions
                var session = await this.facebookSessionClient.LoginAsync(permissions ?? this.Permissions);

                // initialize current session
                this.CurrentSession = session;
                this.SessionStateChanged.RaiseEvent(this, new SessionStateChangedEventArgs(FacebookSessionState.Opened));

                // retrieve information about the current user
                if (this.FetchUserInfo)
                {
                    FacebookClient client = new FacebookClient(session.AccessToken);

                    dynamic result = await client.GetTaskAsync("me");
                    this.CurrentUser = new GraphUser(result);
                    var userInfo = new UserInfoChangedEventArgs(this.CurrentUser);
                    this.UserInfoChanged.RaiseEvent(this, userInfo);
                }
            }
            catch (ArgumentNullException error)
            {
                // TODO: remove when bug in SDK is fixed (the bug happens when you cancel the facebook login dialog)
                var authenticationErrorEventArgs =
                    new AuthenticationErrorEventArgs("Login failure.", error.Message);

                this.AuthenticationError.RaiseEvent(this, authenticationErrorEventArgs);
            }
            catch (InvalidOperationException error)
            {
                // TODO: need to obtain richer information than a generic InvalidOperationException
                var authenticationErrorEventArgs =
                    new AuthenticationErrorEventArgs("Login failure.", error.Message);

                this.AuthenticationError.RaiseEvent(this, authenticationErrorEventArgs);
            }
            catch (FacebookOAuthException error)
            {
                var authenticationErrorEventArgs =
                    new AuthenticationErrorEventArgs("Login failure.", error.Message);

                this.AuthenticationError.RaiseEvent(this, authenticationErrorEventArgs);
            }
        }