예제 #1
0
        private async void webBrowser_Navigating(object sender, NavigatingEventArgs e)
        {
            if (e.Uri.ToString().StartsWith("https://www.facebook.com/connect/login_success.html"))
            {
                e.Cancel = true;

                WebViewBorder.Visibility     = System.Windows.Visibility.Collapsed;
                LoginButtonBorder.Visibility = System.Windows.Visibility.Collapsed;
                LoggedInPanel.Visibility     = System.Windows.Visibility.Visible;

                if (Pulsate.GetCurrentState() != ClockState.Active)
                {
                    Pulsate.RepeatBehavior = RepeatBehavior.Forever;
                    Pulsate.Begin();
                }

                FacebookUser user        = null;
                string       accessToken = "";

                try
                {
                    accessToken = e.Uri.ToString().Substring(e.Uri.ToString().IndexOf("access_token=") + "access_token=".Length);
                    if (accessToken.IndexOf("&") > 0)
                    {
                        accessToken = accessToken.Substring(0, accessToken.IndexOf("&"));
                    }

                    user = await FacebookUserResponse.GetFacebookUser(accessToken);
                }
                catch { }

                if (user == null)
                {
                    if (Pulsate.GetCurrentState() == ClockState.Active)
                    {
                        Pulsate.Stop();
                    }
                    await webBrowser.ClearCookiesAsync();

                    WebViewBorder.Visibility     = System.Windows.Visibility.Collapsed;
                    LoginButtonBorder.Visibility = System.Windows.Visibility.Visible;
                    LoggedInPanel.Visibility     = System.Windows.Visibility.Collapsed;
                    MessageBox.Show("Unable to login using Facebook.  Please try again.");
                }
                else
                {
                    await Authenticate(accessToken, user.Id);
                }
            }
        }
 /// <summary>
 /// Gets information about the user with the specified <code>id</code>.
 /// </summary>
 /// <param name="id">The ID of the user.</param>
 public FacebookUserResponse GetUser(string id)
 {
     return(FacebookUserResponse.ParseResponse(Raw.GetUser(id)));
 }