Exemplo n.º 1
0
 private void Form3_Load(object sender, EventArgs e)
 {
     session = OAuth.Authorize(DecodeKey.GetKey(1), DecodeKey.GetKey(2));
     System.Diagnostics.Process.Start(session.AuthorizeUri.AbsoluteUri);
 }
Exemplo n.º 2
0
        private void TweetButton_Click(object sender, EventArgs e)
        {
            // 認証
            if (!MainIni.Auth)
            {
                if (MessageBox.Show(Properties.Resources.Noauth_MBtext, Properties.Resources.Noauth_MBtitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    Form3 OAuth = new Form3();
                    OAuth.ShowDialog(this);
                    MainIni.Auth = true;
                    TweetText_TextChanged(null, null);
                    TweetStatus.Text = Properties.Resources.Authed;
                }
                return;
            }
            // 固まるからどうにかしなければ
            if (Convert.ToInt16(TweetButton.Text) < 0)
            {
                TweetStatus.Text = Properties.Resources.TextOver;
                return;
            }
            Tokens token = null;

            try {
                token = CoreTweet.Tokens.Create(DecodeKey.GetKey(1), DecodeKey.GetKey(2), MainIni.Token, MainIni.TokenSecret);
            }
            catch (System.Exception ex)  {
                TweetStatus.Text = Properties.Resources.TokenError_status;
                MessageBox.Show(Properties.Resources.TokenError_MBtext + ex.Message, Properties.Resources.Error_MBtitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            var MediaId = new List <long>();

            TweetStatus.Text = Properties.Resources.Tweet_Sending;
            this.Refresh();
            if (Image1.Checked && screen[0] != null)
            {
                MediaId.Add(token.Media.Upload(media: ConvertImageToBytes(screen[0])).MediaId);
            }
            if (Image2.Checked && screen[1] != null)
            {
                MediaId.Add(token.Media.Upload(media: ConvertImageToBytes(screen[1])).MediaId);
            }
            if (Image3.Checked && screen[2] != null)
            {
                MediaId.Add(token.Media.Upload(media: ConvertImageToBytes(screen[2])).MediaId);
            }
            if (Image4.Checked && screen[3] != null)
            {
                MediaId.Add(token.Media.Upload(media: ConvertImageToBytes(screen[3])).MediaId);
            }
            string statustext = TweetText.Text;

            if (FooterMode.Checked)
            {
                statustext += " " + FooterText.Text;
            }
            if (statustext == "" && MediaId.Count == 0)
            {
                TweetStatus.Text = Properties.Resources.NoData;
                return;
            }
            try {
                Status s = token.Statuses.Update(
                    status: statustext,
                    media_ids: MediaId
                    );
            }
            catch (System.Exception ex) {
                TweetStatus.Text = Properties.Resources.SendError_status;
                MessageBox.Show(Properties.Resources.SendError_MBtext + ex.Message, Properties.Resources.Error_MBtitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            TweetText.Text   = "";
            TweetButton.Text = "140";
            TweetStatus.Text = Properties.Resources.Tweet_Sent + System.DateTime.Now.ToString("HH:mm:ss");
        }