示例#1
0
        private void DoWebAuth()
        {
            WebBrowser.Visibility = Visibility.Collapsed;
            PinPanel.Visibility   = Visibility.Collapsed;

            var auth = new SilverlightAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey    = "",
                    ConsumerSecret = ""
                },
                PerformRedirect = authUrl =>
                                  Dispatcher.BeginInvoke(() => HtmlPage.Window.Navigate(new Uri(authUrl)))
            };

            Uri url = HtmlPage.Document.DocumentUri;

            auth.CompleteAuthorize(url, resp =>
                                   Dispatcher.BeginInvoke(() =>
            {
                // you can save these in the db and add logic
                // to look for credentials from db before
                // doing Oauth dance.
                var oauthToken  = auth.Credentials.OAuthToken;
                var accessToken = auth.Credentials.AccessToken;

                switch (resp.Status)
                {
                case TwitterErrorStatus.Success:
                    FriendsPanel.Visibility = Visibility.Visible;
                    break;

                case TwitterErrorStatus.TwitterApiError:
                case TwitterErrorStatus.RequestProcessingException:
                    MessageBox.Show(
                        resp.Exception.ToString(),
                        resp.Message,
                        MessageBoxButton.OK);
                    break;
                }
            }));

            if (!auth.IsAuthorized && !auth.IsAuthorizing)
            {
                auth.BeginAuthorize(url, resp =>
                                    Dispatcher.BeginInvoke(() =>
                {
                    switch (resp.Status)
                    {
                    case TwitterErrorStatus.Success:
                        break;

                    case TwitterErrorStatus.TwitterApiError:
                    case TwitterErrorStatus.RequestProcessingException:
                        MessageBox.Show(
                            resp.Exception.ToString(),
                            resp.Message,
                            MessageBoxButton.OK);
                        break;
                    }
                }));
            }

            twitterCtx = new TwitterContext(auth);
        }
        private void DoWebAuth()
        {
            WebBrowser.Visibility = Visibility.Collapsed;
            PinPanel.Visibility   = Visibility.Collapsed;

            var auth = new SilverlightAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey    = "",
                    ConsumerSecret = ""
                },
                PerformRedirect = authUrl =>
                                  Dispatcher.BeginInvoke(() => HtmlPage.Window.Navigate(new Uri(authUrl)))
            };

            Uri url = HtmlPage.Document.DocumentUri;

            auth.CompleteAuthorize(url, resp =>
                                   Dispatcher.BeginInvoke(() =>
            {
                switch (resp.Status)
                {
                case TwitterErrorStatus.Success:
                    UpdatePanel.Visibility = Visibility.Visible;
                    TweetTextBox.Text      = "Silverlight Web Test, " + DateTime.Now.ToString() + " #linqtotwitter";
                    break;

                case TwitterErrorStatus.TwitterApiError:
                case TwitterErrorStatus.RequestProcessingException:
                    MessageBox.Show(
                        resp.Exception.ToString(),
                        resp.Message,
                        MessageBoxButton.OK);
                    break;
                }
            }));

            if (!auth.IsAuthorized && !auth.IsAuthorizing)
            {
                auth.BeginAuthorize(url, resp =>
                                    Dispatcher.BeginInvoke(() =>
                {
                    switch (resp.Status)
                    {
                    case TwitterErrorStatus.Success:
                        break;

                    case TwitterErrorStatus.TwitterApiError:
                    case TwitterErrorStatus.RequestProcessingException:
                        MessageBox.Show(
                            resp.Exception.ToString(),
                            resp.Message,
                            MessageBoxButton.OK);
                        break;
                    }
                }));
            }

            twitterCtx = new TwitterContext(auth);
        }