Beispiel #1
0
 public void SaveOAuthToken(Token token, long userId, string screenName)
 {
     Settings.Instance.Accounts.First().OAuthToken = token.OAuthToken;
     Settings.Instance.Accounts.First().OAuthTokenSecret = token.OAuthTokenSecret;
     Settings.Instance.Accounts.First().UserId = userId;
     Settings.Instance.Accounts.First().ScreenName = screenName;
     Settings.Instance.Save();
 }
Beispiel #2
0
        public Task Post(string text, ulong? inReplyToStatusId, bool useFooter)
        {
            if (useFooter && !string.IsNullOrEmpty(Settings.Instance.Footer))
                text += " " + Settings.Instance.Footer;

            var cancellation = new CancellationTokenSource();
            RunningTask runningTask = null;

            var token = new Token()
            {
                ConsumerKey = Settings.Instance.ConsumerKey,
                ConsumerSecret = Settings.Instance.ConsumerSecret,
                OAuthToken = Settings.Instance.GetUsingAccount().OAuthToken,
                OAuthTokenSecret = Settings.Instance.GetUsingAccount().OAuthTokenSecret
            };

            var reTask = TwitterApi.Tweets.UpdateApi
                .Create(text, inReplyToStatusId)
                .CallApi(token, cancellation.Token)
                .ContinueWith(t =>
                {
                    RunningTasks.Instance.Remove(runningTask);

                    if (t.Exception == null)
                    {
                        TimelineItemCache.Instance.AddOrMergeTweet(t.Result, true);
                    }
                    else
                    {
                        //TODO:再試行できるようにする
                    }
                });

            runningTask = new RunningTask("投稿中:" + text, reTask, cancellation);
            RunningTasks.Instance.Add(runningTask);

            return reTask;
        }
        public void StartAuthentication()
        {
            this.GettingRequestToken = true;
            TwitterApi.OAuth.RequestTokenApi.Create()
                .CallApi(new Token()
                {
                    ConsumerKey = Settings.Instance.ConsumerKey,
                    ConsumerSecret = Settings.Instance.ConsumerSecret
                })
                .ContinueWith(t =>
                {
                    this.GettingRequestToken = false;

                    if (t.Exception != null)
                    {
                        this.Messenger.Raise(new InformationMessage(
                            "リクエストトークンを取得できませんでした。",
                            "認証失敗",
                            MessageBoxImage.Error,
                            "ShowInformation"
                        ));
                        return;
                    }

                    this.requestToken = t.Result;

                    this.Authenticating = true;
                    this.Messenger.Raise(new InteractionMessage("FocusToPinCodeBox"));

                    ProcessHelper.Start("https://api.twitter.com/oauth/authorize?oauth_token=" + this.requestToken.OAuthToken);
                });
        }