Esempio n. 1
0
        private async void OnAddAccountClickAsync(object sender, RoutedEventArgs e)
        {
            var progdiag = await this.ShowProgressAsync("認証中", "認証処理をしています。しばらくお待ちください。");

            var pincode = PinCodeTextBox.Text;

            try
            {
                var token     = session.GetTokens(pincode);
                var container = new TwitterAccount(token);
                await container.UpdateCache();

                Core.ConfigStore.StaticConfig.accountList.Add(container);
                await progdiag.CloseAsync();

                this.Close();
            }
            catch (Exception ex)
            {
                await this.ShowMessageAsync("エラー",
                                            $"正常に認証できませんでした。PINコードが間違っている可能性があります\n\n{ex}");

                WindowTab.SelectedIndex = 0;
                PinCodeTextBox.Text     = "";
                await progdiag.CloseAsync();
            }
        }
Esempio n. 2
0
 /// <summary>
 /// PINコードを用いて認証します。
 /// </summary>
 /// <param name="pin">PINコード</param>
 /// <returns>成功した場合はTokens</returns>
 public Tokens AuthorizeToken(string pin)
 {
     try
     {
         var t = OAuthSession.GetTokens(pin);
         return(t);
     }
     catch
     {
         return(null);
     }
 }
Esempio n. 3
0
 public MainController(onCopyFunc onCopy)
 {
     this.onCopy        = onCopy;
     LabelText          = getTokenFlg.Select(flg => flg ? "PINコード" : "検索ワード").ToReadOnlyReactiveProperty();
     ButtonText         = getTokenFlg.Select(flg => flg ? "入力" : "検索").ToReadOnlyReactiveProperty();
     showListViewFlg    = getTokenFlg.Select(flg => !flg).ToReadOnlyReactiveProperty();
     SearchStartCommand = SearchWord.Select(s => s.Length != 0).CombineLatest(progressFlg, (x, y) => x & !y).ToReactiveCommand();
     CopyLinkCommand    = SelectTweet.Select(t => t != null).ToReactiveCommand();
     OpenLinkCommand    = SelectTweet.Select(t => t != null).ToReactiveCommand();
     RtRtCommand        = SelectTweet.Select(t => t != null).ToReactiveCommand();
     SearchResult       = searchResult.ToReadOnlyReactiveCollection();
     //
     LoginCommand.Subscribe(_ => Login());
     SearchStartCommand.Subscribe(async _ => {
         if (getTokenFlg.Value)
         {
             // トークン入力処理
             token = session.GetTokens(SearchWord.Value);
             Application.Current.Properties["AccessToken"]       = token.AccessToken;
             Application.Current.Properties["AccessTokenSecret"] = token.AccessTokenSecret;
             getTokenFlg.Value = false;
             SearchWord.Value  = "";
         }
         else
         {
             // 検索処理
             await SearchTweet();
         }
     });
     CopyLinkCommand.Subscribe(_ => {
         string url = "https://twitter.com/" + SelectTweet.Value.User.ScreenName + "/status/" + SelectTweet.Value.Id;
         this.onCopy(url);
     });
     OpenLinkCommand.Subscribe(_ => {
         string url = "https://twitter.com/" + SelectTweet.Value.User.ScreenName + "/status/" + SelectTweet.Value.Id;
         Device.OpenUri(new Uri(url));
     });
     RtRtCommand.Subscribe(_ => {
     });
     //トークンが保存されているかを確かめ、されてない場合に限りログイン処理を行う
     if (Application.Current.Properties.ContainsKey("AccessToken") &&
         Application.Current.Properties.ContainsKey("AccessTokenSecret"))
     {
         token = Tokens.Create(Consumer.Key, Consumer.Secret,
                               Application.Current.Properties["AccessToken"] as string,
                               Application.Current.Properties["AccessTokenSecret"] as string);
     }
     else
     {
         Login();
     }
 }
        //PINコードからアクセストークン発行
        public void GetAccessToken(string pin)
        {
            //ダイアログの認証押したとき

            //アクセストークン取得
            var token = session.GetTokens(pin);

            //アクセストークンほぞん
            Properties.Settings.Default.consumer_key        = consumer_key;
            Properties.Settings.Default.consumer_secret     = consumer_secret;
            Properties.Settings.Default.access_token        = token.AccessToken;
            Properties.Settings.Default.access_token_secret = token.AccessTokenSecret;
            Properties.Settings.Default.Save();

            //ログイン成功ダイアログ
            MessageBox.Show("ログインに成功しました。\n" + token.ScreenName);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            string[] commandArgs = Environment.GetCommandLineArgs();
            if (!(commandArgs.Contains("--consumer-key") && commandArgs.Contains("--consumer-select")) && commandArgs.Length <= 5)
            {
                Console.WriteLine("Usage: " + commandArgs[0] + " --consumer-key <consumer(API) key> --consumer-select <consumer(API) select key>");
                Environment.Exit(1);
            }
            else
            {
                string       consumerKey    = commandArgs[Array.IndexOf(commandArgs, "--consumer-key") + 1];
                string       consumerSelect = commandArgs[Array.IndexOf(commandArgs, "--consumer-select") + 1];
                Uri          oauthUri       = null;
                OAuthSession session        = null;
                try
                {
                    session  = OAuth.Authorize(consumerKey, consumerSelect);
                    oauthUri = session.AuthorizeUri;
                } catch (Exception ex)
                {
                    Console.WriteLine("An error has occurred. Check the value and internet connection.");
                    Console.WriteLine("Error:" + ex);
                    Environment.Exit(1);
                }

                Console.WriteLine("Authentication URL:" + oauthUri);
                Console.WriteLine("Please acsess. after getting PIN, Please input PIN and Enter.");
                string pin    = Console.ReadLine();
                Tokens tokens = null;

                try
                {
                    tokens = session.GetTokens(pin);
                } catch (Exception ex)
                {
                    Console.WriteLine("An error has occurred. Check the value and internet connection.");
                    Console.WriteLine("Error:" + ex);
                    Environment.Exit(1);
                }
                Console.WriteLine("Acess Token(oauth token): " + tokens.AccessToken);
                Console.WriteLine("Acess Token Select(oauth token select): " + tokens.AccessTokenSecret);
                Environment.Exit(0);
            }
        }
Esempio n. 6
0
        private async void TwitterHomeTimelineAsync(string pin)
        {
            /*
             * OAuthによるトークン発行
             */
            Tokens tokens = os.GetTokens(pin);

            /*
             * save Token data
             *
             */


            key keys = new key();

            keys.platform = "twitter";
            keys.keydata.Add(new keydata {
                keyName = "AccessSecret", Value = tokens.AccessTokenSecret
            });
            keys.keydata.Add(new keydata {
                keyName = "AccessToken", Value = tokens.AccessToken
            });

            KeysToken.Add(keys);

            /*
             * xml處理
             */
            xmlSave(KeysToken);

            Thread timelist = new Thread(GetTtitterHomeline);

            timelist.Start();
            opentwitterurl();

            //すでに発行されたトークンを利用
            //Tokens tokens = Tokens.Create(API, secretkey, AccessToken, AccessSecret);
        }
Esempio n. 7
0
        //PINコードからアクセストークン発行
        public async void getAccessToken(string pin)
        {
            //ダイアログの認証押したとき

            //アクセストークン取得
            var token = session.GetTokens(pin);

            //アクセストークンほぞん
            var setting = Windows.Storage.ApplicationData.Current.RoamingSettings;

            setting.Values["consumer_key"]        = consumer_key;
            setting.Values["consumer_secret"]     = consumer_secret;
            setting.Values["access_token"]        = token.AccessToken;
            setting.Values["access_token_secret"] = token.AccessTokenSecret;

            //ログイン成功ダイアログ
            ContentDialog deleteFileDialog = new ContentDialog
            {
                Title             = "Twitterログイン成功",
                Content           = token.ScreenName,
                PrimaryButtonText = "閉じる",
            };
            await deleteFileDialog.ShowAsync();
        }
Esempio n. 8
0
 public void GetToken(String pin)
 {
     tokens = session.GetTokens(pin);
 }