public static string GetAuthUrl() { try { string ConsumerKey = ConfigInfo.ConsumerKey; string ConsumerSecret = ConfigInfo.ConsumerSecret; string AccessToken = ConfigInfo.AccessToken; string AccessSecret = ConfigInfo.AccessSecret; // Credentials for Twitter Authorization gotten by making application in apps.twitter.com ITwitterCredentials AppCredentials = new TwitterCredentials(ConsumerKey, ConsumerSecret, AccessToken, AccessSecret); // Stores twitter oauth Url and recently created tokens var authenticationContext = AuthFlow.InitAuthentication(AppCredentials); // Generates string from authenticationContext AuthUrl = authenticationContext.AuthorizationURL; AuthenticationContext = authenticationContext; } catch (ArgumentException ex) { ExceptionTemplates.ArgumentException(ex); } catch (TwitterException ex) { ExceptionTemplates.TwitterException(ex); } catch (Exception ex) { ExceptionTemplates.GenericException(ex); } return(AuthUrl); }
private static void AutoDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { try { string Username = ConfigInfo.Username; string Password = ConfigInfo.Password; var webBrowser1 = sender as WebBrowser; var username = webBrowser1.Document.GetElementById("username_or_email"); username?.SetAttribute("value", Username); var password = webBrowser1.Document.GetElementById(@"session[password]"); password?.SetAttribute("value", Password); var validate = webBrowser1.Document.GetElementById("allow"); validate?.InvokeMember("click"); string URL = webBrowser1.Document.Url.ToString(); Convert.ToString(URL); if (URL == "https://api.twitter.com/oauth/authorize") { try { string AuthPin = webBrowser1.Document.GetElementById("oauth_pin").InnerText; if (AuthPin != null) { bool isNumber = Regex.IsMatch(AuthPin, @"-?\d+(\.\d+)?"); if (isNumber == true) { Authorization.Authorize(AuthPin); Start.CreateCommands(); webBrowser1.Dispose(); } } } catch (Exception ex) { ExceptionTemplates.GenericException(ex); } } } catch (ArgumentException ex) { ExceptionTemplates.ArgumentException(ex); } catch (TwitterException ex) { ExceptionTemplates.TwitterException(ex); } catch (Exception ex) { ExceptionTemplates.GenericException(ex); } }
private static void ManualDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { try { var webBrowser1 = sender as WebBrowser; Console.WriteLine("Please enter your Twitter Username"); var username = webBrowser1.Document.GetElementById("username_or_email"); username?.SetAttribute("value", Console.ReadLine()); Console.WriteLine("Please enter your Twitter Password"); var password = webBrowser1.Document.GetElementById(@"session[password]"); password?.SetAttribute("value", Console.ReadLine()); Console.Clear(); var validate = webBrowser1.Document.GetElementById("allow"); validate?.InvokeMember("click"); string URL = webBrowser1.Document.Url.ToString(); Convert.ToString(URL); if (URL == "https://api.twitter.com/oauth/authorize") { string AuthPin = webBrowser1.Document.GetElementById("oauth_pin").InnerText; if (AuthPin != null) { bool isNumber = Regex.IsMatch(AuthPin, @"-?\d+(\.\d+)?"); if (isNumber == true) { Authorization.Authorize(AuthPin); webBrowser1.Dispose(); } } } } catch (ArgumentException ex) { ExceptionTemplates.ArgumentException(ex); } catch (TwitterException ex) { ExceptionTemplates.TwitterException(ex); } catch (Exception ex) { ExceptionTemplates.GenericException(ex); } }
public static void Authorize(string AuthCode) { try { ITwitterCredentials UserCredentials = AuthFlow.CreateCredentialsFromVerifierCode(AuthCode, AuthenticationContext); Auth.SetCredentials(UserCredentials); Console.WriteLine("Connected to Twitter"); } catch (ArgumentException ex) { ExceptionTemplates.ArgumentException(ex); } catch (TwitterException ex) { ExceptionTemplates.TwitterException(ex); } catch (Exception ex) { ExceptionTemplates.GenericException(ex); } }