private void auth1_Click(object sender, RoutedEventArgs e) { var code = pin_box.Text; try { token = session.GetTokens(code); } catch (TwitterException ex) { MessageBox.Show("エラーが発生しました、もう一度やり直してください\n" + ex.Message); return; } catch (System.Net.WebException ex) { MessageBox.Show("エラーが発生しました、もう一度やり直してください\n" + ex.Message); return; } if (Properties.Settings.Default.AccessToken == "") { Properties.Settings.Default.AccessToken = token.AccessToken; Properties.Settings.Default.TokenSecret = token.AccessTokenSecret; //Console.WriteLine(token.AccessToken + "/" + token.AccessTokenSecret); } else { Properties.Settings.Default.AccessToken = Properties.Settings.Default.AccessToken + "," + token.AccessToken; Properties.Settings.Default.TokenSecret = Properties.Settings.Default.TokenSecret + "," + token.AccessTokenSecret; } Properties.Settings.Default.Save(); Close(); }
/// <summary> /// アカウントを認証する /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void authMenu_Click(object sender, RoutedEventArgs e) { // Authトークンの再取得のためのセッション再認証 Session = OAuth.Authorize(Session.ConsumerKey, Session.ConsumerSecret); AuthWindow = new AuthWindow(Session); AuthWindow.ShowDialog(); if (!AuthWindow.isOk) { return; } Tokens token; statusBarText.Text = "アカウント認証中..."; try { token = Session.GetTokens(AuthWindow.Pin); } catch { MessageBox.Show("入力されたPINが不正です。"); statusBarText.Text = ""; return; } Tokens.Add(token); UserAccounts.Add(token.Statuses.UserTimeline().First().User); SaveTokens(); authorizedCountMenu.Header = $"認証済み:{Tokens.Count}"; statusBarText.Text = "アカウント認証完了"; authMenu.IsChecked = true; }
public void SessionStart() { Console.Write("[APIKey]>"); APIKey = Console.ReadLine(); Console.Write("[APISecret]>"); APISecret = Console.ReadLine(); if (AllInput()) { try { OAuth.OAuthSession session = OAuth.Authorize(APIKey, APISecret); Console.WriteLine("承認してください : "); Console.WriteLine(session.AuthorizeUri.AbsoluteUri); Console.WriteLine(); Console.Write("[PIN]>"); string pin = Console.ReadLine(); token = session.GetTokens(pin); } catch (TwitterException) { Console.WriteLine("--- セッションを開始できませんでした。\a"); } } else { Console.WriteLine("--- セッション開始に必要な情報が不足しています。"); } }
void auth() { Console.WriteLine("Debug:OK"); //初回起動時 SetContentView(Resource.Layout.Main); Button button = FindViewById <Button>(Resource.Id.MyButton); Button button1 = FindViewById <Button>(Resource.Id.button1); EditText pin = FindViewById <EditText>(Resource.Id.editText1); string code; button.Click += (sender, e) => { //token発行 session = OAuth.Authorize(twitter.ConsumerKey, twitter.ConsumerSecret); string url = session.AuthorizeUri.ToString(); var uri = Android.Net.Uri.Parse(url); var intent = new Intent(Intent.ActionView, uri); StartActivity(intent); pin.Enabled = true; }; pin.TextChanged += (sender, e) => { code = pin.Text; int n; if (code.Length == 7 && int.TryParse(code, out n) && button1.Enabled == false) { button1.Enabled = true; } else if (button1.Enabled == true) { button1.Enabled = false; } }; button1.Click += (sender, e) => { code = pin.Text; try { token = session.GetTokens(code); } catch (TwitterException ex) { Toast.MakeText(this, "エラーが発生しました、もう一度やり直してください\n" + ex.Message, ToastLength.Long).Show(); return; } catch (System.Net.WebException ex) { Toast.MakeText(this, "エラーが発生しました、もう一度やり直してください\n" + ex.Message, ToastLength.Long).Show(); return; } var editor = prefs.Edit(); editor.PutString("AccessToken", token.AccessToken); editor.PutString("AccessTokenSecret", token.AccessTokenSecret); editor.Commit(); //Dispose(); layout1(); }; }
public static void authorizing(String code) { t = s.GetTokens(code); string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + accessTokenFilePath; StreamWriter writeFile = new StreamWriter(path, false, Encoding.GetEncoding("utf-16")); writeFile.WriteLine(t.AccessToken); writeFile.WriteLine(t.AccessTokenSecret); writeFile.Close(); currentApp.authorized(); }
private void GetToken(string text) { var t = session.GetTokens(text); MainWindow.TokenPublisher(t); Data.AccessToken = t.AccessToken; Data.SecretToken = t.AccessTokenSecret; Data.Save(); this.Close(); }
public Boolean enterPinCode(string pinCode) { tokens = session.GetTokens(pinCode); // get the oauth tokens for the entered pin code if (tokens != null) { return(true); } else { throw new TwitterAuthException("Unable to get the tokens for user."); } }
public Boolean enterPinCode(string pinCode) { Tokens = Session.GetTokens(pinCode); // get the oauth tokens for the entered pin code if (Tokens != null) { screenName = Tokens.ScreenName.ToString(); return(true); } else { throw new Exception("Unable to get the tokens for user."); } }
public void Auth(string pinCode) { if (authSession == null) { // 先にCreateAuthUri()する必要がある throw new InvalidOperationException(); } if (Account == null) { var token = authSession.GetTokens(pinCode); Account = new Settings.Account(token.AccessToken, token.AccessTokenSecret); } }
/// <summary> /// ピンコード認証を実行し、Token取得 /// </summary> public void GetInputPincode() { pincode = pincodeInputField.text; try { token = consumerKey.GetTokens(pincode); SceneManager.LoadScene("MenuScene"); } catch (Exception ex) { Debug.Log(ex.Message); discliption.text = "認証に失敗しました。コードが間違っているか、期限が切れています。"; discliption.color = Color.red; } }
public bool GetTokens(string verifier, out string accessToken, out string accessTokenSecret) { accessToken = null; accessTokenSecret = null; try { tokens = session.GetTokens(verifier); accessToken = tokens.AccessToken; accessTokenSecret = tokens.AccessTokenSecret; return(true); } catch { return(false); } }
/// <summary> /// トークンを取得し、マネージャーを生成します。 /// </summary> /// <param name="user">ログインするユーザー名、新規の場合認証モードになります。</param> /// <param name="isSentLogtoTwitter">Twitterにログを送る場合true</param> public TwitterManager(string user, bool isSentLogtoTwitter) { this._isSentLogtoTwitter = isSentLogtoTwitter; if (!File.Exists(UserdataConfig)) { goto NewUser; } //ファイルのロード using (StreamReader reader = new StreamReader(UserdataConfig, Encoding.UTF8)) { Console.WriteLine("Loading UserFile."); string line; while ((line = reader.ReadLine()) != null) { int eqindex = line.IndexOf('='); string name = line.Substring(0, eqindex); if (name != user) { continue; } string keys = line.Substring(eqindex + 1); int commaindex = keys.IndexOf(','); this.Token = Tokens.Create(ApiKey, ApiSecret, keys.Substring(0, commaindex), keys.Substring(commaindex + 1)); Console.WriteLine("Accept user {0}", user); LogTweet("Loggin from Tweet Extractor."); return; } } NewUser: OAuth.OAuthSession session = OAuth.Authorize(ApiKey, ApiSecret); Console.WriteLine("NewUser Name: {0}", user); Console.WriteLine("Access here: {0}", session.AuthorizeUri); System.Diagnostics.Process.Start(session.AuthorizeUri.ToString()); Console.Write("PinCode: "); this.Token = session.GetTokens(Console.ReadLine()); LogTweet("Loggin from Tweet Extractor."); //ファイルへトークンの書き込み using (StreamWriter writer = new StreamWriter(UserdataConfig, true, Encoding.UTF8)) { writer.WriteLine($"{user}={this.Token.AccessToken},{this.Token.AccessTokenSecret}"); } }
//private void cancelButton_Click(object sender, RoutedEventArgs e) //{ //} private void okButton_Click(object sender, RoutedEventArgs e) { // http://msdn.microsoft.com/ja-jp/library/system.text.regularexpressions.regex.aspx // http://msdn.microsoft.com/ja-jp/library/az24scfc.aspx 正規表現言語 - クイック リファレンス // PINに数字以外を含む場合,認証に移行しない if (string.IsNullOrEmpty(pinTextBox.Text) || System.Text.RegularExpressions.Regex.IsMatch(pinTextBox.Text, @"\D")) { MessageBox.Show("Type numeric characters"); pinTextBox.Clear(); return; } try { // PIN認証 TwitterMainWindows owner = new TwitterMainWindows(); owner.tokens = session.GetTokens(pinTextBox.Text); // トークン保存 //Properties.Settings.Default.AccessToken = owner.tokens.AccessToken; //Properties.Settings.Default.AccessTokenSecret = owner.tokens.AccessTokenSecret; //Properties.Settings.Default.ScreenName = owner.tokens.ScreenName; //Properties.Settings.Default.Save(); saveOAuthSession("AccessToken", owner.tokens.AccessToken); saveOAuthSession("AccessTokenSecret", owner.tokens.AccessTokenSecret); saveOAuthSession("ScreenName", owner.tokens.ScreenName); // 表示調整 owner.updatescreennameLabel(owner.tokens.ScreenName); MessageBox.Show("verified: " + owner.tokens.ScreenName + "\r\n" + "twitter画面をリロードしてね"); } catch (Exception ex) { // やり直し MessageBox.Show(ex.Message); initAuthrize(); } }
private void button1_Click(object sender, EventArgs e) { string pin = textBox1.Text; Tokens tokens = null; try { tokens = session.GetTokens(pin); } catch { if (MessageBox.Show("認証に失敗しました\n認証画面をもう一度表示しますか?", "エラー", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { Form3_Load(null, null); } else { return; } } ((Form1)this.Owner).MainIni.Token = tokens.AccessToken; ((Form1)this.Owner).MainIni.TokenSecret = tokens.AccessTokenSecret; ((Form1)this.Owner).MainIni.Auth = true; this.Close(); }
private void okButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(pinTextBox.Text) || System.Text.RegularExpressions.Regex.IsMatch(pinTextBox.Text, @"\D")) { // MessageBox.Show("Type numeric characters"); var dialog = new ModernDialog1("Type numeric characters"); dialog.ShowDialog(); pinTextBox.Clear(); return; } try { // PIN認証 //MainWindow2 owner = (MainWindow2)this.Owner; //SettingWindow owner = (SettingWindow)this.Owner; tokens = session.GetTokens(pinTextBox.Text); // トークン保存 Properties.Settings.Default.AccessToken = tokens.AccessToken; Properties.Settings.Default.AccessTokenSecret = tokens.AccessTokenSecret; Properties.Settings.Default.ScreenName = tokens.ScreenName; Properties.Settings.Default.Save(); // 表示調整 //owner.updatescreennameLabel(owner.tokens.ScreenName); // MessageBox.Show("verified: " + tokens.ScreenName); var dialog = new ModernDialog1("verified: " + tokens.ScreenName + "一旦このアプリを再起動してください。"); dialog.ShowDialog(); pinTextBox.Clear(); // Close(); } catch (Exception ex) { // やり直し //MessageBox.Show(ex.Message); var dialog = new ModernDialog1(ex.Message); dialog.ShowDialog(); initAuthrize(); } }
// トークンの生成 public static void CreateToken(string pin) { // PIN コードの入力 Tokens = Session.GetTokens(pin); }