/// <summary> /// Handles the Click event of the facebookAuthInBrowserButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void FacebookAuthInBrowserButtonClick(object sender, RoutedEventArgs e) { string code; try { var faw = new FacebookAuthWindow(_facebook); faw.ShowDialog(); if (string.IsNullOrWhiteSpace(faw.Code)) { throw new Exception("Invalid response from server. (No tokens were returned.)"); } else { code = faw.Code; } } catch (Exception ex) { TaskDialog.Show(new TaskDialogOptions { MainIcon = VistaTaskDialogIcon.Error, Title = "Facebook OAuth", MainInstruction = "Error", Content = "An error occurred while generating an authorization link.", ExpandedInfo = ex.Message, CustomButtons = new[] { "OK" } }); return; } try { var tokens = _facebook.FinishAuthorizationWithPin(code); Settings.Set("Facebook OAuth", _facebook.Tokens = tokens); if (_facebook.Tokens.Count == 4) { facebookUserName.Text = _facebook.Tokens[1]; facebookUserLink.NavigateUri = new Uri("http://facebook.com/profile.php?id=" + _facebook.Tokens[0]); facebookNoAuthMsg.Visibility = Visibility.Collapsed; facebookOkAuthMsg.Visibility = Visibility.Visible; } } catch (Exception ex) { TaskDialog.Show(new TaskDialogOptions { MainIcon = VistaTaskDialogIcon.Error, Title = "Facebook OAuth", MainInstruction = "Error", Content = "An error occurred while getting the tokens for the specified PIN.", ExpandedInfo = ex.Message, CustomButtons = new[] { "OK" } }); } }