示例#1
0
        ITwitterAuthorizer PerformAuthorization()
        {
            // validate that credentials are present
            if (string.IsNullOrWhiteSpace(twitterConsumerKey) ||
                string.IsNullOrWhiteSpace(twitterConsumerSecret))
            {
                MessageBox.Show(@"Error while setting " +
                                "App.config/appSettings. \n\n" +
                                "You need to provide your twitterConsumerKey and twitterConsumerSecret in App.config \n" +
                                "Please visit http://dev.twitter.com/apps for more info.\n");

                return(null);
            }

            // configure the OAuth object
            var auth = new PinAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey    = twitterConsumerKey,
                    ConsumerSecret = twitterConsumerSecret
                },
                UseCompression           = true,
                GoToTwitterAuthorization = pageLink => Process.Start(pageLink),
                GetPin = () =>
                {
                    // this executes after user authorizes, which begins with the call to auth.Authorize() below.

                    PinWindow pinw = new PinWindow();
                    pinw.Owner = this;
                    if (pinw.ShowDialog() == true)
                    {
                        return(pinw.Pin);
                    }
                    else
                    {
                        return("");
                    }
                }
            };

            // start the authorization process (launches Twitter authorization page).
            try
            {
                auth.Authorize();
            }
            catch (WebException ex)
            {
                /*MessageBox.Show("Unable to authroize with Twitter right now. Please check pin number", "Twitter Archive Eraser",
                 *  MessageBoxButton.OK, MessageBoxImage.Information);
                 */
                MessageBox.Show(ex.Message);

                return(null);
            }

            return(auth);
        }
示例#2
0
        IAuthorizer PerformAuthorization()
        {
            // validate that credentials are present
            if (string.IsNullOrWhiteSpace(twitterConsumerKey) ||
                string.IsNullOrWhiteSpace(twitterConsumerSecret) ||
                string.IsNullOrWhiteSpace(twitterConsumerKeyDM) ||
                string.IsNullOrWhiteSpace(twitterConsumerSecretDM))
            {
                MessageBox.Show(@"Error while setting " +
                                "App.config/appSettings. \n\n" +
                                "You need to provide your twitterConsumerKey and twitterConsumerSecret in App.config \n" +
                                "Please visit http://dev.twitter.com/apps for more info.\n");

                return(null);
            }

            InMemoryCredentialStore credentialStore = null;

            if (needsDMPermissions)
            {
                credentialStore = new InMemoryCredentialStore()
                {
                    ConsumerKey    = twitterConsumerKeyDM,
                    ConsumerSecret = twitterConsumerSecretDM
                };
            }
            else
            {
                credentialStore = new InMemoryCredentialStore()
                {
                    ConsumerKey    = twitterConsumerKey,
                    ConsumerSecret = twitterConsumerSecret
                };
            }

            // configure the OAuth object
            var auth = new PinAuthorizer
            {
                CredentialStore          = credentialStore,
                GoToTwitterAuthorization = pageLink => Process.Start(pageLink),
                GetPin = () =>
                {
                    // ugly hack
                    string pin = "";

                    Dispatcher.Invoke((Action)
                                      (() =>
                    {
                        PinWindow pinw = new PinWindow();
                        pinw.Owner = this;
                        if (pinw.ShowDialog() == true)
                        {
                            pin = pinw.Pin;
                        }
                        else
                        {
                            pin = "";
                        }
                    }
                                      ));

                    return(pin);
                }
            };

            return(auth);
        }
        IAuthorizer PerformAuthorization()
        {
            // validate that credentials are present
            if (string.IsNullOrWhiteSpace(twitterConsumerKey) ||
                string.IsNullOrWhiteSpace(twitterConsumerSecret))
            {
                MessageBox.Show(@"Error while setting " +
                                "App.config/appSettings. \n\n" +
                                "You need to provide your twitterConsumerKey and twitterConsumerSecret in App.config \n" +
                                "Please visit http://dev.twitter.com/apps for more info.\n");

                return(null);
            }

            // configure the OAuth object
            var auth = new PinAuthorizer
            {
                CredentialStore = new InMemoryCredentialStore
                {
                    ConsumerKey    = twitterConsumerKey,
                    ConsumerSecret = twitterConsumerSecret
                },
                GoToTwitterAuthorization = pageLink => Process.Start(pageLink),
                GetPin = () =>
                {
                    // ugly hack
                    string pin = "";

                    Dispatcher.Invoke((Action)
                                      (() =>
                    {
                        PinWindow pinw = new PinWindow();
                        pinw.Owner = this;
                        if (pinw.ShowDialog() == true)
                        {
                            pin = pinw.Pin;
                        }
                        else
                        {
                            pin = "";
                        }
                    }
                                      ));

                    return(pin);
                }
            };

            return(auth);

            // start the authorization process (launches Twitter authorization page).
            try
            {
                Task t = auth.BeginAuthorizeAsync();
                t.Wait();
            }
            catch (WebException ex)
            {
                MessageBox.Show(ex.Message
                                + "\n\nPlease make sure that:"
                                + "\n\t- your computer's date/time is accurate;"
                                + "\n\t- you entered the exact PIN returned by Twitter.",
                                "Twitter Archive Eraser");

                return(null);
            }

            return(auth);
        }
        ITwitterAuthorizer PerformAuthorization()
        {
            // validate that credentials are present
            if (string.IsNullOrWhiteSpace(twitterConsumerKey) ||
                string.IsNullOrWhiteSpace(twitterConsumerSecret))
            {
                MessageBox.Show(@"Error while setting " +
                                    "App.config/appSettings. \n\n" +
                                    "You need to provide your twitterConsumerKey and twitterConsumerSecret in App.config \n" +
                                    "Please visit http://dev.twitter.com/apps for more info.\n");

                return null;
            }

            // configure the OAuth object
            var auth = new PinAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey = twitterConsumerKey,
                    ConsumerSecret = twitterConsumerSecret
                },
                UseCompression = true,
                GoToTwitterAuthorization = pageLink => Process.Start(pageLink),
                GetPin = () =>
                {
                    // this executes after user authorizes, which begins with the call to auth.Authorize() below.

                    PinWindow pinw = new PinWindow();
                    pinw.Owner = this;
                    if (pinw.ShowDialog() == true)
                        return pinw.Pin;
                    else
                        return "";
                }
            };

            // start the authorization process (launches Twitter authorization page).
            try
            {
                auth.Authorize();
            }
            catch (WebException ex)
            {
                /*MessageBox.Show("Unable to authroize with Twitter right now. Please check pin number", "Twitter Archive Eraser",
                    MessageBoxButton.OK, MessageBoxImage.Information);
                */
                MessageBox.Show(ex.Message);

                return null;
            }

            return auth;
        }
        IAuthorizer PerformAuthorization()
        {
            // validate that credentials are present
            if (string.IsNullOrWhiteSpace(twitterConsumerKey) 
                || string.IsNullOrWhiteSpace(twitterConsumerSecret)
                || string.IsNullOrWhiteSpace(twitterConsumerKeyDM) 
                || string.IsNullOrWhiteSpace(twitterConsumerSecretDM))
            {
                MessageBox.Show(@"Error while setting " +
                                    "App.config/appSettings. \n\n" +
                                    "You need to provide your twitterConsumerKey and twitterConsumerSecret in App.config \n" +
                                    "Please visit http://dev.twitter.com/apps for more info.\n");

                return null;
            }

            InMemoryCredentialStore credentialStore = null;
            if(needsDMPermissions)
            {
                credentialStore = new InMemoryCredentialStore()
                {
                    ConsumerKey = twitterConsumerKeyDM,
                    ConsumerSecret = twitterConsumerSecretDM
                };
            }
            else
            {
                credentialStore = new InMemoryCredentialStore()
                {
                    ConsumerKey = twitterConsumerKey,
                    ConsumerSecret = twitterConsumerSecret
                };
            }

            // configure the OAuth object
            var auth = new PinAuthorizer
            {
                CredentialStore = credentialStore,
                GoToTwitterAuthorization = pageLink => Process.Start(pageLink),
                GetPin = () =>
                {
                    // ugly hack
                    string pin = "";

                    Dispatcher.Invoke((Action)
                    (() =>
                        {
                            PinWindow pinw = new PinWindow();
                            pinw.Owner = this;
                            if (pinw.ShowDialog() == true)
                                pin = pinw.Pin;
                            else
                                pin = "";
                        }
                    ));

                    return pin;
                }
            };

            return auth;
        }