private void GetAccountPin() { CoreTweet.OAuth.OAuthSession session = null; if (string.IsNullOrEmpty(ConsumerKey.Text) && string.IsNullOrEmpty(ConsumerSecret.Text)) { session = CoreTweet.OAuth.Authorize(Properties.Settings.Default.TwitterAPIKey, Properties.Settings.Default.TwitterAPISecret); System.Diagnostics.Process.Start(session.AuthorizeUri.ToString()); } else if (!string.IsNullOrEmpty(ConsumerKey.Text) && !string.IsNullOrEmpty(ConsumerSecret.Text)) { session = CoreTweet.OAuth.Authorize(ConsumerKey.Text, ConsumerSecret.Text); System.Diagnostics.Process.Start(session.AuthorizeUri.ToString()); } var dialog = new AccountAuthorizationPin(); dialog.Owner = this; dialog.ShowDialog(); try { tokens = CoreTweet.OAuth.GetTokens(session, dialog.Pin); Close(); } catch (CoreTweet.TwitterException e) { MessageBox.Show(e.Message, "Error"); } catch (NullReferenceException) { } }
// 認証処理 private void OAuth() { if (textbox_pin.Text == "") { //何も入力されていない場合 Method.message("Error", "PINコードを入力してください"); } else if (Regex.IsMatch(textbox_pin.Text, "/^[0-9]+$/")) { // 半角数字以外の文字列が入力されていた場合 Method.message("Error", "半角数字を入力してください"); } else { try { CoreTweet.Tokens tokens = CoreTweet.OAuth.GetTokens(session, textbox_pin.Text); Properties.Settings.Default.AccessToken = tokens.AccessToken; Properties.Settings.Default.AccessTokenSecret = tokens.AccessTokenSecret; EndWatch(); Method.logfile("Info", "Authentication success"); Hide(); new MainForm().Show(); } catch (CoreTweet.TwitterException) { // PINコードが間違っている場合 Method.message("Error", "正しいPINコードを入力してください"); } } }
public Form1() { InitializeComponent(); lastImageName = ""; clvshell = new ClovershellConnection() { AutoReconnect = true, Enabled = true }; SNSConfig.createTemplateIf(); configTwitter = SNSConfig.load(); if (null != configTwitter) { if (configTwitter.isProductionToken()) { displayTwitterAccountValid(true); twitterTokens = CoreTweet.Tokens.Create(configTwitter.ConsumerKey, configTwitter.ConsumerSecret, configTwitter.AccessToken, TestNetworkError ? "0000" : configTwitter.AccessTokenSecret); } else { labelTwhint.Text = "Generate tokens on Twitter web before using."; labelTwhint.Visible = true; } } showState("Please connect your console before taking screenshot.", 0); }
private async void Button_Click(object sender, RoutedEventArgs e) { if (PINText != null && PINText.Length != 0) { ButtonText = "処理中"; ButtonEnable = false; try { tokens = await CoreTweet.OAuth.GetTokensAsync(session, PINText); var userdata = new UserData(); userdata.UserID = tokens.UserId.ToString(); userdata.UserName = tokens.ScreenName; userdata.AccessToken = tokens.AccessToken; userdata.AccessTokenSecret = tokens.AccessTokenSecret; var rdl = new UserDataLoader(filename); rdl.Userdata = userdata; rdl.UserDataSave(); } catch (CoreTweet.TwitterException exception) { string caption = "エラー"; string message = "次のエラーが発生しました\n" + exception.Message.ToString(); var button = MessageBoxButton.OK; MessageBox.Show(message, caption, button); } finally { Close(); } } }
public TwitterUser(CoreTweet.Tokens tokens) { UserId = tokens.UserId; Token = tokens.AccessToken; Secret = tokens.AccessTokenSecret; ScreenName = tokens.ScreenName; Filter = new TwitterNotificationFilter(); }
public static CoreTweet.UserResponse GetUserInfomation(CoreTweet.Tokens tokens) { if (tokens == null) { return(null); } return(tokens.Account.VerifyCredentials()); }
public Token(CToken token, User user) { Id = user.Id; ConsumerKey = token.ConsumerKey; ConsumerSecret = token.ConsumerSecret; AccessToken = token.AccessToken; AccessTokenSecret = token.AccessTokenSecret; UserId = user.Id; User = user; }
public void ShowLoginWindow() { using (var vm = new LoginWindowViewModel()) { vm.Consumer = settingManager.Setting.Consumer; Messenger.Raise(new TransitionMessage(vm, "ShowLoginWindowCommand")); settingManager.Setting.Account = vm.Account; var token = new CoreTweet.Tokens { ConsumerKey = settingManager.Setting.Consumer.ConsumerKey, ConsumerSecret = settingManager.Setting.Consumer.ConsumerSecret, AccessToken = settingManager.Setting.Account.AccessToken, AccessTokenSecret = settingManager.Setting.Account.AccessTokenSecret }; token.Statuses.Update("bananerてすと"); } }
public void initTwitter(Boolean showDialog) { //初期化。引数はログイン無いときダイアログだすか //ログイン情報取得 if (setting.Values["consumer_key"] != null) { var consumer_key = setting.Values["consumer_key"].ToString(); var consumer_secret = setting.Values["consumer_secret"].ToString(); var access_token = setting.Values["access_token"].ToString(); var access_token_secret = setting.Values["access_token_secret"].ToString(); twitter = CoreTweet.Tokens.Create(consumer_key, consumer_secret, access_token, access_token_secret); } else { if (showDialog) { //ログインしてね showLoginMessage(); } } //ListView読み込み setListViewData(); }
public void initTwitter(Boolean showDialog) { //初期化。引数はログイン無いときダイアログだすか //ログイン情報取得 if (Properties.Settings.Default.consumer_key != "") { var consumer_key = Properties.Settings.Default.consumer_key; var consumer_secret = Properties.Settings.Default.consumer_secret; var access_token = Properties.Settings.Default.access_token; var access_token_secret = Properties.Settings.Default.access_token_secret; twitter = CoreTweet.Tokens.Create(consumer_key, consumer_secret, access_token, access_token_secret); } else { if (showDialog) { //ログインしてね showLoginMessage(); } } //ListView読み込み setListViewData(); }
private void butPIN_Click(object sender, EventArgs e) { tokens = CoreTweet.OAuth.GetTokens(Session, txtPIN.Text); }
private void InitializeAccount() { using (var conn = new SQLiteConnection("Data Source=" + dbPath)) { conn.Open(); using (var command = conn.CreateCommand()) { command.CommandText = "select * from account"; using (var reader = command.ExecuteReader()) { while (reader.Read()) { tokens = CoreTweet.Tokens.Create(reader["consumerkey"].ToString(), reader["consumersecret"].ToString(), reader["accesstoken"].ToString(), reader["accesstokensecret"].ToString()); } } } conn.Close(); } if (tokens == null) { AuthorizeAccount(); } }
private void AuthorizeAccount() { var dialog = new AccountAuthorization(); dialog.Owner = this; dialog.ShowDialog(); tokens = dialog.tokens; using (var conn = new SQLiteConnection("Data Source=" + dbPath)) { conn.Open(); using (var command = conn.CreateCommand()) { command.CommandText = "insert into account (consumerkey,consumersecret,accesstoken,accesstokensecret) values('" + tokens.ConsumerKey + "', '" + tokens.ConsumerSecret + "', '" + tokens.AccessToken + "', '" + tokens.AccessTokenSecret + "')"; command.ExecuteNonQuery(); } conn.Close(); } }
private bool LoadTokens() { var udl = new UserDataLoader(App.userprofile_filename); if (udl.Userdata != null) { tokens = udl.GetCoreTweetTokens(App.consumer_key, App.consumer_secret); userdata = udl.Userdata; UserNameText = userdata.UserName; StatusText = "認証成功"; StartButtonEnable = true; return true; } else { StatusText = "認証してください"; StartButtonEnable = false; return false; } }
public void Search(string query) { images.Clear(); Task.Factory.StartNew(() => { // トークンを取得 if (tokens == null) { tokens = CoreTweet.Tokens.Create( SecretSetting.Default.ConsumerKey, SecretSetting.Default.ConsumerSecret, SecretSetting.Default.AccessToken, SecretSetting.Default.AccessTokenSecret ); if (tokens == null) { SearchError(this, EventArgs.Empty); return; } } // Httpエンコード var word = HttpUtility.HtmlEncode(query); // 検索し、結果を取得 var dic = new Dictionary <string, object>(); dic.Add("q", "filter:images " + word); dic.Add("include_entities", true); dic.Add("count", (int)numericUpDown1.Value); if (comboBox1.SelectedIndex > 0) { dic.Add("result_type", SearchMethods[comboBox1.SelectedIndex]); } if (dateTimePicker1.Checked) { var date = string.Format("{0:0000}-{1:00}-{2:00}", dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, dateTimePicker1.Value.Day); dic.Add("until", date); } if (checkBox1.Checked) { dic.Add("since_id", numericUpDown2.Value); } if (checkBox2.Checked) { dic.Add("max_id", numericUpDown3.Value); } CoreTweet.SearchResult result = null; try { result = tokens.Search.Tweets(dic); } catch { SearchError(this, EventArgs.Empty); return; } Parallel.For(0, result.Count, i => { try { var res = result[i]; if (res.Entities.Media != null) { foreach (var m in res.Entities.Media) { var wc = new System.Net.WebClient(); Stream stream = wc.OpenRead(m.MediaUrl.AbsoluteUri); var idx = m.MediaUrl.LocalPath.LastIndexOf('/'); if (idx < 0) { idx = 0; } var sub = m.MediaUrl.LocalPath.Substring(idx + 1); var idx1 = sub.LastIndexOf(":large"); var idx2 = sub.LastIndexOf("-large"); if (idx1 > 0) { sub = sub.Substring(0, idx1); } else if (idx2 > 0) { sub = sub.Substring(0, idx2); } var bitmap = new System.Drawing.Bitmap(stream); if (sub.LastIndexOf('.') == -1) { sub += "." + GetFileFormat(bitmap); } var image = new ImageData() { Bitmap = bitmap, FileName = sub, SourceURL = m.ExpandedUrl.AbsoluteUri, }; lock (images) { images.Add(image); ImageLoaded(this, new ImageLoadedEventArgs() { Index = images.Count - 1, ImageData = image }); } stream.Close(); } } } catch { } }); SearchFinished(this, EventArgs.Empty); }); }