public TwitterManager(string consumerKey, string consumerSecret, string accessTokenKey, string accessTokenSecret, bool threadless = false) { this.ConsumerKey = consumerKey; this.ConsumerSecret = consumerSecret; this.AccessTokenKey = accessTokenKey; this.AccessTokenSecret = accessTokenSecret; this.Threadless = threadless; this.Credential = new TwitterCredential() { ApiKey = consumerKey, ApiSecret = consumerSecret, TokenKey = accessTokenKey, TokenSecret = accessTokenSecret }; if (!threadless) { Auth.ApplicationCredentials = new TwitterCredentials( consumerKey, consumerSecret, accessTokenKey, accessTokenSecret ); } }
public static void SaveCredentials(string username, string twitterUsername, string twitterPassword) { using (var db = new ezFixUpDataContext()) { var credentials = db.TwitterCredentials.FirstOrDefault(tc => tc.u_username == username); if (credentials == null) { credentials = new TwitterCredential {u_username = username}; db.TwitterCredentials.InsertOnSubmit(credentials); } credentials.tc_username = twitterUsername; credentials.tc_password = twitterPassword; db.SubmitChanges(); } }
private async void Parse(Stream stream, string text) { var cookieStr = await ParseInner(stream, text); var twitCred = await Task.Factory.StartNew(() => TwitterCredential.GetCredential(cookieStr)); if (twitCred != null) { MessageBox.Show(string.Format(Lang.LoginWindowWeb__AddSuccess, twitCred.ScreenName), Lang.Name, MessageBoxButtons.OK, MessageBoxIcon.Information); this.TwitterCredential = twitCred; } else { MessageBox.Show(Lang.LoginWindowWeb__AddError, Lang.Name, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } this.Close(); }
private void ctlWeb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (this.m_webBrowser.Url.Host == "twitter.com" && this.m_webBrowser.Url.AbsolutePath == "/") { if (this.m_logined) { return; } this.m_logined = true; this.m_webBrowser.Stop(); Task.Factory.StartNew(() => { var cookie = NativeMethods.GetCookies(TwitterUri).GetCookieHeader(TwitterUri); var twitCred = TwitterCredential.GetCredential(cookie); if (twitCred != null) { this.Invoke(new Action(() => MessageBox.Show(this, string.Format(Lang.LoginWindowWeb_AddSuccess, twitCred.ScreenName), Lang.Name, MessageBoxButtons.OK, MessageBoxIcon.Information))); this.TwitterCredential = twitCred; } else { this.Invoke(new Action(() => MessageBox.Show(this, Lang.LoginWindowWeb_AddError, Lang.Name, MessageBoxButtons.OK, MessageBoxIcon.Exclamation))); } this.Invoke(new Action(this.Close)); }); return; } try { var doc = (HTMLDocument)this.m_webBrowser.Document.DomDocument; try { this.m_webBrowser.Document.InvokeScript("eval", new object[] { "$(document).contextmenu(function(){return false;});" }); } catch { } doc.RemoveElementByClass("topbar js-topbar"); doc.RemoveElementByClass("clearfix mobile has-sms"); doc.RemoveElementByClass("subchck"); doc.body.style.backgroundColor = "#FFF"; IHTMLElement elem; elem = doc.GetElementByClassName("message-text"); if (elem != null) { var msg = elem.innerText; if (!string.IsNullOrWhiteSpace(msg)) { MessageBox.Show(this, msg, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } elem.RemoveElement(); } elem = doc.getElementById("page-container"); if (elem != null) { elem.style.padding = "3px"; elem.style.border = ""; } this.m_webBrowser.Visible = true; } catch (Exception ex) { SentrySdk.CaptureException(ex); } }
private void ctlWeb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (string.IsNullOrWhiteSpace(e.Url.Host)) { return; } if (!e.Url.Host.EndsWith("twitter.com")) { this.m_webBrowser.Navigate("https://mobile.twitter.com/login?redirect_after_login=https%3A%2F%2Ftwitter.com%2F"); return; } if (e.Url.AbsolutePath == "/") { if (this.m_logined) { return; } this.m_logined = true; this.m_webBrowser.Stop(); Task.Factory.StartNew(() => { var cookie = NativeMethods.GetCookies(TwitterUri).GetCookieHeader(TwitterUri); var twitCred = TwitterCredential.GetCredential(cookie); this.Invoke(new Action(() => { if (twitCred != null) { MessageBox.Show(string.Format(Lang.LoginWindowWeb__AddSuccess, twitCred.ScreenName), Lang.Name, MessageBoxButtons.OK, MessageBoxIcon.Information); this.TwitterCredential = twitCred; } else { MessageBox.Show(Lang.LoginWindowWeb__AddError, Lang.Name, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } this.Close(); })); }); return; } try { var doc = (HTMLDocument)this.m_webBrowser.Document.DomDocument; try { this.m_webBrowser.Document.InvokeScript("eval", new object[] { "$(document).contextmenu(function(){return false;});" }); } catch { } IHTMLElement elem; if (e.Url.AbsolutePath.StartsWith("/login")) { doc.RemoveElementByClass("chromeless"); doc.RemoveElementByClass("footer"); doc.body.style.backgroundColor = "#FFF"; doc.body.style.border = "none"; elem = doc.GetElementByClassName("message"); if (elem != null) { var msg = elem.innerText; if (!string.IsNullOrWhiteSpace(msg) && !msg.Contains("이전 버전")) { MessageBox.Show(msg, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } } doc.RemoveElementByClass("toast"); elem = doc.getElementById("container"); if (elem != null) { elem.style.padding = "3px"; elem.style.width = "auto"; } doc.body.ExecuteChildren(le => { le.style.background = null; le.style.border = null; }); } else if (e.Url.AbsolutePath.StartsWith("/account/login_verification")) { doc.RemoveElementByClass("TopNav"); doc.RemoveElementByClass("PageHeader Edge"); doc.RemoveElementsByClass("Help"); elem = doc.GetElementByClassName("Section"); if (elem != null) { var c = (IHTMLElementCollection)elem.children; if (c != null) { foreach (IHTMLElement child in c) { if (child.tagName == "p") { child.RemoveElement(); break; } } } } elem = doc.getElementById("error-message"); if (elem != null) { var msg = elem.innerText; if (!string.IsNullOrWhiteSpace(msg)) { MessageBox.Show(msg, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } elem.RemoveElement(); } elem = doc.getElementById("ResponsiveLayout"); if (elem != null) { elem.style.padding = "3px"; elem.style.border = "none"; } } #if DEBUG Console.WriteLine(this.m_webBrowser.Document.Body.OuterHtml); #endif } catch (Exception ex) { SentrySdk.CaptureException(ex); } this.m_webBrowser.Visible = true; }
public TwitterStream(TwitterCredential credential) : this(credential.ApiKey, credential.ApiSecret, credential.TokenKey, credential.TokenSecret) { }