void _browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            try
            {
                String uri = e.Uri.ToString();

                if (uri.StartsWith("https://www.facebook.com/connect/login_success.html") || uri.StartsWith("http://www.facebook.com/connect/login_success.html") ||
                    uri.StartsWith("https://m.facebook.com/connect/login_success.html") || uri.StartsWith("http://m.facebook.com/connect/login_success.html") ||
                    uri.StartsWith("https://www.facebook.com/v2.0/connect/login_success.html") || uri.StartsWith("http://www.facebook.com/v2.0/connect/login_success.html") ||
                    uri.StartsWith("https://m.facebook.com/v2.0/connect/login_success.html") || uri.StartsWith("http://m.facebook.com/v2.0/connect/login_success.html") ||
                    uri.StartsWith("https://www.facebook.com/v1.0/connect/login_success.html") || uri.StartsWith("http://www.facebook.com/v1.0/connect/login_success.html") ||
                    uri.StartsWith("https://m.facebook.com/v1.0/connect/login_success.html") || uri.StartsWith("http://m.facebook.com/v1.0/connect/login_success.html") ||
                    uri.StartsWith(_app_info.RedirectLink))
                {
                    if (uri.EndsWith("#_=_"))
                    {
                        uri = uri.Substring(0, uri.Length - 4);
                    }
                    String queryString = e.Uri.Query.ToString();
                    try
                    {
                        IEnumerable <KeyValuePair <string, string> > pairs = UriToolKits.ParseQueryString(queryString);
                        string    code     = KeyValuePairUtils.GetValue(pairs, "code");
                        string    tokenurl = FacebookClient.Instance.getAccessTokenRequestUrl(_app_info, code);
                        WebClient client   = new WebClient();
                        client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(AccessTokenDownloadCompleted);
                        client.DownloadStringAsync(new Uri(tokenurl));
                    }
                    catch (Exception ex)
                    {
                        fail();
                    }
                }
                else if (uri.StartsWith("https://m.facebook.com/dialog/oauth/write") ||
                         uri.StartsWith("http://m.facebook.com/dialog/oauth/write") ||
                         uri.StartsWith("https://m.facebook.com/v2.0/dialog/oauth/write") ||
                         uri.StartsWith("http://m.facebook.com/v2.0/dialog/oauth/write") ||
                         uri.StartsWith("https://m.facebook.com/v1.0/dialog/oauth/write") ||
                         uri.StartsWith("http://m.facebook.com/v1.0/dialog/oauth/write"))
                {
                    string url = FacebookClient.Instance.getLoginUrl(_app_info);
                    _browser.Source = new Uri(url);
                }
            }
            catch (Exception ex2)
            {
                fail();
                Debug.WriteLine(ex2.Message);
            }
        }
        void ExchangeAccessTokenCompleted(object sender, UploadStringCompletedEventArgs e)
        {
            // Acquire access_token and expires timestamp
            IEnumerable <KeyValuePair <string, string> > pairs = UriToolKits.ParseQueryString(e.Result);
            string accessToken = KeyValuePairUtils.GetValue(pairs, "access_token");

            if (accessToken != null && !accessToken.Equals(""))
            {
                MessageBox.Show("Access Token Exchange Failed");
                return;
            }

            // Save access_token
            FacebookClient.Instance.AccessToken = accessToken;
            FacebookClient.Instance.PostMessageOnWall(txtStatus.Text, new UploadStringCompletedEventHandler(PostMessageOnWallCompleted));
        }
 void AccessTokenDownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
 {
     if (!e.Cancelled && e.Error == null)
     {
         try {
             string data = e.Result;
             data = "?" + data;
             IEnumerable <KeyValuePair <string, string> > pairs = UriToolKits.ParseQueryString(data);
             string accessToken = KeyValuePairUtils.GetValue(pairs, "access_token");
             string expires     = KeyValuePairUtils.GetValue(pairs, "expires");
             success(accessToken, expires);
         } catch (Exception ex) {
             fail();
         }
     }
     else
     {
         fail();
     }
 }