Esempio n. 1
0
        /// <summary>
        /// tokens.json からアカウント情報を読み込み、その有効性を検証します
        /// </summary>
        static private async Task <Tokens> _LoadAndVerifyCredentialsAsync(CredentialsJsonFile config)
        {
            var ck  = config.ConsumerKey;
            var cs  = config.ConsumerSecret;
            var at  = config.AccessToken;
            var ats = config.AccessTokenSecret;

            var defaultTokensKey = "";

            var isNotDefaultTokens = ck != defaultTokensKey && cs != defaultTokensKey && at != defaultTokensKey && ats != defaultTokensKey;

            if (isNotDefaultTokens)
            {
                var tokens = Tokens.Create(ck, cs, at, ats);

                // トークンの有効性を検証
                try
                {
                    var account = await tokens.Account.VerifyCredentialsAsync(include_entities : false, skip_status : true);

                    return(tokens);
                }
                catch { }
            }
            return(null);
        }
Esempio n. 2
0
        public override async Task ToggleEnable()
        {
            Enabled = !Enabled;

            var config = await CredentialsJsonFile.LoadAsync();

            config.Enabled = Enabled;
            await config.SaveAsync();
        }
Esempio n. 3
0
        public override async Task Setup()
        {
            var config = await CredentialsJsonFile.LoadAsync();

            var twitter = await _LoadAndVerifyCredentialsAsync(config);

            if (twitter == null)
            {
                return;
            }

            twitter.UserId = long.Parse(twitter.AccessToken.Split('-')[0]);
            var user = await twitter.Users.ShowAsync(twitter.UserId);

            twitter.ScreenName = user.ScreenName;

            _Twitter = twitter;

            Enabled = config.Enabled;
        }
Esempio n. 4
0
        public override async Task <bool> Install()
        {
            var config = await CredentialsJsonFile.LoadAsync();

            var twitter = await _LoadAndVerifyCredentialsAsync(config);

            if (twitter == null)
            {
                MessageBox.Show(
                    "有効なTwitterトークンの設定が必要です。twitter.jsonの中身を編集してからアプリケーションを再実行してください。",
                    "Information",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);

                return(false);
            }
            await Setup();

            MessageBox.Show($"Hello @{_Twitter.ScreenName}", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

            return(true);
        }