public virtual void SendTweetWithMedia(SendTweetWithMediaOptions options, Action<TwitterStatus, TwitterResponse> action)
		{
			var status = options.Status;
			var possibly_sensitive = options.PossiblySensitive;
			var in_reply_to_status_id = options.InReplyToStatusId;
			var lat = options.Lat;
			var @long = options.@Long;
			var place_id = options.PlaceId;
			var display_coordinates = options.DisplayCoordinates;
            var images = options.Images;

            WithHammock(WebMethod.Post, action, "statuses/update_with_media", images, FormatAsString, "?status=", status, "&possibly_sensitive=", possibly_sensitive, "&in_reply_to_status_id=", in_reply_to_status_id, "&lat=", lat, "&long=", @long, "&place_id=", place_id, "&display_coordinates=", display_coordinates);
		}
		public virtual Task<TwitterResponse<TwitterStatus>> SendTweetWithMediaAsync(SendTweetWithMediaOptions options)
		{
			var status = options.Status;
			var possibly_sensitive = options.PossiblySensitive;
			var in_reply_to_status_id = options.InReplyToStatusId;
			var lat = options.Lat;
			var @long = options.@Long;
			var place_id = options.PlaceId;
			var display_coordinates = options.DisplayCoordinates;
			 var images = options.Images;
				
			
			return ExecuteRequest<TwitterStatus>(HttpMethod.Post, "statuses/update_with_media", images, FormatAsString, "?status=", status, "&possibly_sensitive=", possibly_sensitive, "&in_reply_to_status_id=", in_reply_to_status_id, "&lat=", lat, "&long=", @long, "&place_id=", place_id, "&display_coordinates=", display_coordinates);
		}
        /// <summary>
        ///     Sets an user status.
        /// </summary>
        /// <param name="status">Status entity.</param>
        public async Task SetStatusAsync(TwitterStatus status)
        {
            // Pass your credentials to the service
            string consumerKey = _settings.TwitterConsumerKey;
            string consumerSecret = _settings.TwitterConsumerSecret;

            // Authorize
            var service = new TwitterService(consumerKey, consumerSecret);
            service.AuthenticateWith(status.Token, status.TokenSecret);

            // Send message
            TweetSharp.TwitterStatus result;
            if (string.IsNullOrEmpty(status.ScreenshotUrl))
            {
                var tweet = new SendTweetOptions { Status = status.Message };
                result = service.SendTweet(tweet);
            }
            else
            {
                using (var httpClient = new HttpClient())
                {
                    HttpResponseMessage response = await httpClient.GetAsync(status.ScreenshotUrl);
                    if (!response.IsSuccessStatusCode)
                    {
                        throw new BadRequestException(response.ReasonPhrase);
                    }

                    Stream stream = await response.Content.ReadAsStreamAsync();
                    var tweet = new SendTweetWithMediaOptions
                    {
                        Status = status.Message,
                        Images = new Dictionary<string, Stream>
                        {
                            { "media", stream }
                        }
                    };

                    result = service.SendTweetWithMedia(tweet);
                }
            }

            // Check result status
            if (result != null)
            {
                return;
            }

            // Check response status code
            switch (service.Response.StatusCode)
            {
                case HttpStatusCode.Unauthorized:
                case HttpStatusCode.BadRequest:
                    // Invalid credentials or request data
                    throw new BadRequestException(service.Response.Response);

                case HttpStatusCode.Forbidden:
                    throw new ForbiddenException(service.Response.Response);

                case (HttpStatusCode)429:
                    throw new TooManyRequestsException(service.Response.Response);
            }

            // Twitter internal errors
            if ((int)service.Response.StatusCode >= 500)
            {
                throw new BadGatewayException(service.Response.Response);
            }

            string message = string.Format("Unable to send tweet. Status code {0}: {1}", service.Response.StatusCode, service.Response);
            throw new InternalServerErrorException(message);
        }
		public virtual IAsyncResult BeginSendTweetWithMedia(SendTweetWithMediaOptions options)
		{
			var status = options.Status;
			var possibly_sensitive = options.PossiblySensitive;
			var in_reply_to_status_id = options.InReplyToStatusId;
			var lat = options.Lat;
			var @long = options.@Long;
			var place_id = options.PlaceId;
			var display_coordinates = options.DisplayCoordinates;
			 var images = options.Images;
				

			return BeginWithHammock<TwitterStatus>(_client, WebMethod.Post, "statuses/update_with_media", images, FormatAsString, "?status=", status, "&possibly_sensitive=", possibly_sensitive, "&in_reply_to_status_id=", in_reply_to_status_id, "&lat=", lat, "&long=", @long, "&place_id=", place_id, "&display_coordinates=", display_coordinates);
		}
Esempio n. 5
0
        private void TweetPost_Click(object sender, EventArgs e)
        {
            Text = "TwitterPost - 投稿中…";
            try
            {
                // ハッシュタグ
                string hashtag = null;

                if (HashTag.Checked == true)
                {
                    // 有効
                    hashtag = " #艦これ";
                    Settings.Instance.hashtag_s = "True";
                }
                else if (HashTag.Checked == false)
                {
                    // 無効
                    hashtag = "";
                    Settings.Instance.hashtag_s = "False";
                }

                // xml保存
                Settings.SaveToXmlFile();

                // POST、画像つきPOST
                if (Thumbnail.ImageLocation != "")
                {
                    // 画像が選択されていた場合PictureBoxからパス取得
                    string photo = Thumbnail.ImageLocation;
                    var stream = new FileStream(photo, FileMode.Open);
                    SendTweetWithMediaOptions opt = new SendTweetWithMediaOptions();

                    // Tweet本文 + 画像
                    opt.Status = TweetText.Text + hashtag;
                    opt.Images = new Dictionary<string, Stream> { { "image", stream } };

                    // イメージ付きでPOST
                    service.SendTweetWithMedia(opt);

                    // 自動的に閉じる
                    Close();
                }
                else
                {
                    // テキストのみPOST
                    service.SendTweet(new SendTweetOptions { Status = TweetText.Text + hashtag });

                    // 自動的に閉じる
                    Close();
                }
            }
            catch (Exception ex)
            {
                // 例外発生時メッセージ
                MessageBox.Show("例外が発生しました\n" + ex, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 6
0
        public void TweetWithImage()
        {
            try
            {
                //ステータスリスト
                List<TwitterService> ResponseList = new List<TwitterService>();

                //各アカウントでつぶやく
                foreach (Core.ApplicationSetting.AccountClass account in AccountList)
                {
                    //ファイルのストリームを取得
                    System.IO.Stream stream = Song.getAlbumArtworkFileStream();
                    TwitterService service = new TwitterService(Core.Twitter.CONSUMERKEY, Core.Twitter.CONSUMERSECRET);
                    service.AuthenticateWith(account.Token, account.TokenSecret);
                    SendTweetWithMediaOptions opt = new SendTweetWithMediaOptions();
                    opt.Status = Core.Replace.ReplaceText(TweetText, Song); // ツイートする内容
                    //テキストを自動的に削るやつ
                    if (AutoDeleteText == true && opt.Status.Length > 117)
                    {
                        opt.Status = opt.Status.Remove(114);//...の三文字分含めて削除
                        opt.Status += "...";
                    }
                    //opt.Status = HttpUtility.UrlEncode(opt.Status);
                    opt.Images = new Dictionary<string, System.IO.Stream> { { "image", stream } };
                    //Luaの関数を走らせる
                    try
                    {
                        bool luaRet = (bool)luaFunc.Call(Song, opt, isCustomTweet)[0];
                        if (luaRet == true)
                        {
                            service.SendTweetWithMedia(opt);
                            ResponseList.Add(service);
                        }
                    }
                    catch (Exception ex2)
                    {
                        //Luaが失敗しても死なないようにする
                        Trace.WriteLine("Lua error.");
                        Trace.WriteLine(ex2.ToString());
                        service.SendTweetWithMedia(opt);
                        ResponseList.Add(service);
                    }
                    stream.Close();
                    stream.Dispose();
                }
                //完了イベントを投げる
                onProcessFinished(ResponseList);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("[TwitterPost ERROR]" + ex.ToString());
            }
        }
        public void Tweet(string message, string hashTag, string picture)
        {
            if (CalcurateTweetLength(message, hashTag, picture) > 140) {
                throw new ArgumentException("文字数が多すぎます。");
            }

            if (twitterService_ == null) {
                twitterService_ = new TwitterService(consumerKey_, consumerSecret_);
                twitterService_.AuthenticateWith(accessToken_, accessTokenSecret_);
            }

            var str = CreateTweetText(message, hashTag);
            if (picture != null) {
                SendTweetWithMediaOptions opt = new SendTweetWithMediaOptions();
                using (var fs = new FileStream(picture, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    opt.Images = new Dictionary<string, Stream> { { "image", fs } };
                    opt.Status = str;
                    twitterService_.SendTweetWithMedia(opt);
                }
            }
            else {
                var opt = new SendTweetOptions();
                opt.Status = str;
                twitterService_.SendTweet(opt);
            }
        }
Esempio n. 8
0
        /// <summary>
        ///     Uploading image, done on a different thread. </br>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"> Contains the </param>
        private void m_oWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            List<Object> args = (List<Object>) e.Argument;

            //Get the elements
            String message = (String) args[0];
            BitmapSource bitsource = (BitmapSource) args[1];
            Stream stream = args[2] as MemoryStream;

            Console.WriteLine("Uploading image now");

            var service = new TwitterService(OAuthConsumerKey, OAuthConsumerSecret);
            service.AuthenticateWith(OAuthToken, OAuthTokenSecret);

            SendTweetWithMediaOptions options = new SendTweetWithMediaOptions();

            options.Status = message;
            var dic = new Dictionary<string, Stream>();
            dic.Add(message, stream);
            options.Images = dic;
            service.SendTweetWithMedia(options);
            //Report 100% completion on operation completed
            worker.ReportProgress(100);
        }