Exemplo n.º 1
0
        public ITweet PublishTweetWithMedia(string text, byte[] media)
        {
            var parameters = new PublishTweetOptionalParameters();

            parameters.MediaBinaries.Add(media);

            return(PublishTweet(text, parameters));
        }
Exemplo n.º 2
0
        public ITweet PublishTweetInReplyTo(string text, long tweetId)
        {
            var parameters = new PublishTweetOptionalParameters();

            parameters.InReplyToTweetId = tweetId;

            return(PublishTweet(text, parameters));
        }
Exemplo n.º 3
0
        public ITweet PublishTweetWithMedia(string text, long mediaId)
        {
            var parameters = new PublishTweetOptionalParameters();

            parameters.MediaIds.Add(mediaId);

            return(PublishTweet(text, parameters));
        }
Exemplo n.º 4
0
        public ITweet PublishTweetInReplyTo(string text, ITweetIdentifier tweet)
        {
            var parameters = new PublishTweetOptionalParameters();

            parameters.InReplyToTweet = tweet;

            return(PublishTweet(text, parameters));
        }
Exemplo n.º 5
0
        private bool PostTweet(List <string> tweetDetails, PostDetail postDetail)
        {
            _logger.Info($"Posting Tweet Id: {postDetail.Id}");
            _logger.Info($"UpVotes: {postDetail.UpVotes} DownVotes: {postDetail.DownVotes}");
            ITweet initialTweet = null;

            foreach (var tweetStr in tweetDetails)
            {
                try
                {
                    if (initialTweet == null)
                    {
                        initialTweet = Tweet.PublishTweet(tweetStr);
                    }
                    else
                    {
                        PublishTweetOptionalParameters optParams;

                        if (postDetail.IsText)
                        {
                            optParams = new PublishTweetOptionalParameters
                            {
                                InReplyToTweet = initialTweet
                            };
                        }
                        else
                        {
                            optParams = new PublishTweetOptionalParameters
                            {
                                InReplyToTweet = initialTweet,
                                Medias         = new List <IMedia> {
                                    GetMediaToBytes(tweetStr)
                                }
                            };

                            postDetail.IsText = true;
                        }
                        var reply = Tweet.PublishTweet(tweetStr, optParams);
                        initialTweet = reply;
                    }
                }
                catch (Exception ex)
                {
                    _logger.Info(ex.Message);
                }

                if (initialTweet == null)
                {
                    _logger.Info("Failed: Initial Tweet refused to post\n");
                    return(false);
                }
            }

            _logger.Info("Success..\n");
            return(true);
        }
Exemplo n.º 6
0
 public ActionResult Anasayfa(string Gonderi)
 {
     Auth.ExecuteOperationWithCredentials(_credentials, () =>
     {
         var publishOptions = new PublishTweetOptionalParameters();
         return(Tweetinvi.Tweet.PublishTweet(Gonderi, publishOptions));
     }
                                          );
     return(View("tweet_yazdir"));
 }
Exemplo n.º 7
0
        public ActionResult Yaz(string benim_tweetim)
        {
            Auth.ExecuteOperationWithCredentials(_credentials, () =>
            {
                var publishOptions = new PublishTweetOptionalParameters();
                return(Tweetinvi.Tweet.PublishTweet(benim_tweetim, publishOptions));
            }
                                                 );

            return(View());
        }
Exemplo n.º 8
0
        public ITweet PostTweet(string text, IEnumerable <IMedia> media = null)
        {
            IPublishTweetOptionalParameters parms = new PublishTweetOptionalParameters();

            if (media != null)
            {
                parms.Medias.AddRange(media);
            }

            return(Auth.ExecuteOperationWithCredentials(TwitterCredentials, () => {
                return Tweet.PublishTweet(text, parms);
            }));
        }
Exemplo n.º 9
0
        public IActionResult Index(TweetForm form)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.RedirectToAction("Index", "Home"));
            }

            // 認証情報から Twitter の資格情報を取得
            var rawUserCreds = this.User.Claims.Single(m => m.Type == ClaimTypes.UserData).Value;
            var userCreds    = JsonConvert.DeserializeObject <TwitterCredentials>(rawUserCreds);

            // そのままではツイートできないので資格情報をセットする
            Auth.SetCredentials(userCreds);

            var data = new List <(DateTime Shot, byte[] Binaries)>();

            // アップロードされたファイルを扱いやすい形式に変換
            foreach (var uploadFile in form.UploadFiles)
            {
                using var fs = uploadFile.OpenReadStream();
                using var ms = new MemoryStream();
                fs.CopyTo(ms);

                fs.Seek(0, SeekOrigin.Begin);
                using var bmp = Bitmap.FromStream(fs);
                var shot = bmp.GetShotDateTime() ?? DateTime.Now;

                data.Add((shot, ms.ToArray()));
            }

            // 撮影日順にデータを並べてからツイート
            foreach (var datum in data.OrderBy(m => m.Shot))
            {
                if (this.HttpContext.RequestAborted.IsCancellationRequested)
                {
                    break;
                }

                var publishOptions = new PublishTweetOptionalParameters();
                publishOptions.MediaBinaries.Add(datum.Binaries);

                var tweet = string.IsNullOrEmpty(form.Text) ? "[date]" : form.Text;
                tweet = tweet.Replace("[date]", datum.Shot.ToString("d"));

                Tweet.PublishTweet(tweet, publishOptions);
            }

            this.Notice("ツイートが完了しました");
            return(this.RedirectToAction("Index", "Home"));
        }
Exemplo n.º 10
0
        public ITweet PublishTweetWithVideo(string text, byte[] video)
        {
            var media = _uploadQueryExecutor.UploadVideo(video);

            if (media == null || media.MediaId == null || !media.HasBeenUploaded)
            {
                throw new OperationCanceledException("The tweet cannot be published as some of the medias could not be published!");
            }

            var parameters = new PublishTweetOptionalParameters();

            parameters.MediaIds.Add((long)media.MediaId);

            return(PublishTweet(text, parameters));
        }
Exemplo n.º 11
0
        public IActionResult Test()
        {
            var data = new List <(DateTime Shot, byte[] Binaries, string FilePath)>();

            var path = @"D:\ftproot2\1024600";

            foreach (var filePath in Directory.EnumerateFiles(path, "*.png"))
            {
                var fileInfo = new System.IO.FileInfo(filePath);

                using var fs = System.IO.File.OpenRead(filePath);
                using var ms = new MemoryStream();
                fs.CopyTo(ms);

                data.Add((fileInfo.LastWriteTime, ms.ToArray(), filePath));
            }

            // そのままではツイートできないので資格情報をセットする
            var userCreds = this.HttpContext.Session.Get <TwitterCredentials>("UserCreds");

            Auth.SetCredentials(userCreds);

            // 撮影日順にデータを並べてからツイート
            foreach (var datum in data.OrderBy(m => m.Shot))
            {
                if (this.HttpContext.RequestAborted.IsCancellationRequested)
                {
                    break;
                }

                var publishOptions = new PublishTweetOptionalParameters();
                publishOptions.MediaBinaries.Add(datum.Binaries);

                // ツイートが成功するとそのオブジェクトが返ってくる
                var tweet = Tweet.PublishTweet(datum.Shot.ToString("d"), publishOptions);
                if (tweet != null)
                {
                    System.IO.File.Delete(datum.FilePath);
                }
                else
                {
                    return(this.Content("failed."));
                }
            }

            return(this.Content("succeeded"));
        }
Exemplo n.º 12
0
        public void TweetLostPet(LostPet lostPet)
        {
            var context = GeoPetContext.GetInstance();
            var pet     = context.Pets.Where(x => x.Email.Equals(lostPet.Email) && x.Name.Equals(lostPet.Name)).SingleOrDefault();

            byte[] imgBytes;
            using (WebClient client = new WebClient())
            {
                imgBytes = client.DownloadData(new Uri(pet.ImageUrl));
            }
            //Generate any parameters to be included
            var publishParams = new PublishTweetOptionalParameters();

            publishParams.MediaBinaries = new List <byte[]> {
                imgBytes
            };

            Tweet.PublishTweet($"Se perdió {pet.Name} :(, ayudanos a encontrarl@", publishParams);
        }
Exemplo n.º 13
0
        public void TweetFoundPet(LostPet lostPet)
        {
            var context = GeoPetContext.GetInstance();
            var pet     = context.Pets.Where(x => x.Email.Equals(lostPet.Email) && x.Name.Equals(lostPet.Name)).SingleOrDefault();

            byte[] imgBytes;
            using (WebClient client = new WebClient())
            {
                imgBytes = client.DownloadData(new Uri(pet.ImageUrl));
            }

            var publishParams = new PublishTweetOptionalParameters();

            publishParams.MediaBinaries = new List <byte[]> {
                imgBytes
            };

            Tweet.PublishTweet($"Encontraron a {pet.Name}!!! :)", publishParams);
        }
 public async Task <IActionResult> Post(IFormCollection form)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (Auth.Credentials != null && Tweetinvi.User.GetAuthenticatedUser(Auth.Credentials) != null)
     {
         try
         {
             string strTweet = string.Empty;
             if (form.Any() && form.Keys.Contains("TweetString"))
             {
                 strTweet = form["TweetString"];
             }
             IFormFile file = form.Files.FirstOrDefault();
             if (!string.IsNullOrEmpty(strTweet))
             {
                 ITweet publishedTweet = Auth.ExecuteOperationWithCredentials(Auth.Credentials, () =>
                 {
                     var publishOptions = new PublishTweetOptionalParameters();
                     if (file != null)
                     {
                         var fileBytes = GetByteArrayFromFile(file);
                         publishOptions.MediaBinaries.Add(fileBytes);
                     }
                     return(Tweetinvi.Tweet.PublishTweet(strTweet, publishOptions));
                 });
                 bool success = publishedTweet != null;
                 var  routeValueParameters = new Dictionary <string, object>();
                 routeValueParameters.Add("id", publishedTweet == null ? (Nullable <long>)null : publishedTweet.Id);
                 routeValueParameters.Add("actionPerformed", "Publish");
                 routeValueParameters.Add("success", success);
                 return(Ok());
             }
         }
         catch (Exception e)
         {
             throw;
         }
     }
     return(StatusCode(StatusCodes.Status500InternalServerError));
 }
Exemplo n.º 15
0
        public static long PublishTweet(string tweet_string, long?inReplyToTweetId)
        {
            Tweetinvi.Core.Interfaces.ITweet newTweet = null;
            if (inReplyToTweetId == 0)
            {
                newTweet = Tweet.PublishTweet(tweet_string);
            }
            else
            {
                newTweet = Tweet.PublishTweet(tweet_string, new PublishTweetOptionalParameters {
                    InReplyToTweetId = inReplyToTweetId
                });
            }
            PublishTweetOptionalParameters parameters = new PublishTweetOptionalParameters();

            parameters.InReplyToTweetId = newTweet.Id;

            return(newTweet.Id);
            //            newTweet.
        }
Exemplo n.º 16
0
        public ActionResult Index(string tweet, HttpPostedFileBase file)
        {
            var fileBytes = GetByteArrayFromFile(file);

            var publishedTweet = Auth.ExecuteOperationWithCredentials(_credentials, () =>
            {
                var publishOptions = new PublishTweetOptionalParameters();
                if (fileBytes != null)
                {
                    publishOptions.MediaBinaries.Add(fileBytes);
                }

                return(Tweet.PublishTweet(tweet, publishOptions));
            });

            var routeValueParameters = new RouteValueDictionary();

            routeValueParameters.Add("id", publishedTweet == null ? (Nullable <long>)null : publishedTweet.Id);
            routeValueParameters.Add("actionPerformed", "Publish");
            routeValueParameters.Add("success", publishedTweet != null);
            return(RedirectToAction("TweetPublished", routeValueParameters));
        }
Exemplo n.º 17
0
        public void PostTweet(HpbStatistic hpbStatistic, string message, TwitterNotificationTypes type)
        {
            var userCredentials = Auth.CreateCredentials(Configuration["Twitter:ConsumerKey"], Configuration["Twitter:ConsumerSecret"],
                                                         Configuration["Twitter:UserToken"], Configuration["Twitter:UserSecret"]);

            AuthenticatedUser = User.GetAuthenticatedUser(userCredentials);

            if (type == TwitterNotificationTypes.STATUS_UPDATE)
            {
                byte[] status_update_post = File.ReadAllBytes("status_update_" + hpbStatistic.Id + ".jpg");

                var publishedTweet = Auth.ExecuteOperationWithCredentials(userCredentials, () =>
                {
                    var publishOptions = new PublishTweetOptionalParameters();
                    if (status_update_post != null)
                    {
                        publishOptions.MediaBinaries.Add(status_update_post);
                    }

                    return(Tweet.PublishTweet(message, publishOptions));
                });
            }
        }
Exemplo n.º 18
0
        public static void Tweet_PublishTweetWithGeo(string text)
        {
            const double latitude = 37.7821120598956;
            const double longitude = -122.400612831116;

            var publishParameters = new PublishTweetOptionalParameters();
            publishParameters.Coordinates = new Coordinates(latitude, longitude);

            var tweet = Tweet.PublishTweet(text, publishParameters);

            Console.WriteLine(tweet.IsTweetPublished);
        }
Exemplo n.º 19
0
        public static ITweet Tweet_PublishTweetWithImage(string text, string filePath, string filepath2 = null)
        {
            byte[] file1 = File.ReadAllBytes(filePath);

            var publishMultipleImages = filepath2 != null;

            // Create a tweet with a single image
            if (publishMultipleImages)
            {
                var publishParameters = new PublishTweetOptionalParameters
                {
                    MediaBinaries = new[]
                    {
                        file1,
                        File.ReadAllBytes(filepath2)
                    }.ToList()
                };

                return Tweet.PublishTweet(text, publishParameters);
            }
            else
            {
                return Tweet.PublishTweetWithImage(text, file1);
            }
        }
Exemplo n.º 20
0
        internal void Tweet(NotificationType type, TwitterObject rec = null)
        {
            List <TwitterObject> list = null;

            if (rec != null)
            {
                list = new List <TwitterObject> {
                    rec
                };
            }
            else if (type != NotificationType.Restock)
            {
                if (type != NotificationType.Atc)
                {
                    if (type != NotificationType.Paypal)
                    {
                        list = (from x in Global.SETTINGS.TWITTER
                                where x.TwitterType == TwitterObject.TwitterMessageEnum.Checkout
                                select x).ToList <TwitterObject>();
                    }
                    else
                    {
                        list = (from x in Global.SETTINGS.TWITTER
                                where x.TwitterType == TwitterObject.TwitterMessageEnum.PayPal
                                select x).ToList <TwitterObject>();
                    }
                }
                else
                {
                    list = (from x in Global.SETTINGS.TWITTER
                            where x.TwitterType == TwitterObject.TwitterMessageEnum.Atc
                            select x).ToList <TwitterObject>();
                }
            }
            else
            {
                list = (from x in Global.SETTINGS.TWITTER
                        where x.TwitterType == TwitterObject.TwitterMessageEnum.Restock
                        select x).ToList <TwitterObject>();
            }
            if (list != null)
            {
                foreach (TwitterObject obj2 in list)
                {
                    try
                    {
                        string consumerKeySecret = obj2.ConsumerKeySecret;
                        string accessToken       = obj2.AccessToken;
                        string accessTokenSecret = obj2.AccessTokenSecret;
                        string msg = obj2.Message;
                        if (rec != null)
                        {
                            msg = "TESTING MESSAGE";
                        }
                        else
                        {
                            msg = msg.Replace("#product_url#", this._url);
                            msg = msg.Replace("#product_title#", this._productName);
                            msg = msg.Replace("#time#", DateTime.Now.ToLocalTime().ToString("dd/MM/yy hh:mm:sstt", CultureInfo.InvariantCulture));
                            msg = msg.Replace("#rnd#", "(" + _rnd.Next(0, 20).ToString() + ")");
                            msg = msg.Replace("#paypal#", this._task.PaypalLink);
                            msg = msg.Replace("#orderno#", this._task.OrderNo);
                            msg = msg.Replace("#profile_name#", this._task.CheckoutProfile);
                            msg = msg.Replace("#size#", this._task.PickedSize);
                            msg = msg.Replace("#website#", this._task.HomeUrl);
                            msg = msg.Replace("#task_name#", this._task.Name);
                        }
                        if (this._task != null)
                        {
                            Global.SETTINGS.PROFILES.First <ProfileObject>(x => x.Id == this._task.CheckoutId);
                            if (this._task.Login)
                            {
                                msg = msg.Replace("#username#", this._task.Username);
                                msg = msg.Replace("#password#", this._task.Password);
                            }
                        }
                        TwitterCredentials credentials = new TwitterCredentials(obj2.ConsumerKey, consumerKeySecret, accessToken, accessTokenSecret);
                        Auth.SetCredentials(credentials);
                        if (msg.Contains("#img#") && !string.IsNullOrEmpty(this._task.ImgUrl))
                        {
                            msg = msg.Replace("#img#", "");
                            IMedia media = Upload.UploadImage(new WebClient().DownloadData(this._task.ImgUrl));
                            PublishTweetOptionalParameters publishTweetOptionalParameters = new PublishTweetOptionalParameters();
                            List <IMedia> list1 = new List <IMedia> {
                                media
                            };
                            publishTweetOptionalParameters.Medias = list1;
                            Tweetinvi.Tweet.PublishTweet(msg, publishTweetOptionalParameters);
                        }
                        else
                        {
                            Auth.ExecuteOperationWithCredentials <ITweet>(credentials, () => Tweetinvi.Tweet.PublishTweet(msg, null));
                        }
                    }
                    catch (Exception exception)
                    {
                        if (this._task != null)
                        {
                            Global.Logger.Error($"Task '{this._task.Name}': error sending tweet", exception);
                        }
                        else
                        {
                            Global.Logger.Error("Error sending tweet test message", exception);
                        }
                    }
                }
            }
        }
Exemplo n.º 21
0
        public ITweet PublishTweetWithVideo(string text, byte[] video)
        {
            var media = _uploadQueryExecutor.UploadVideo(video, "video/mp4", null);
            if (media == null || media.MediaId == null || !media.HasBeenUploaded)
            {
                throw new OperationCanceledException("The tweet cannot be published as some of the medias could not be published!");
            }

            var parameters = new PublishTweetOptionalParameters();
            parameters.MediaIds.Add((long)media.MediaId);

            return PublishTweet(text, parameters);
        }
Exemplo n.º 22
0
        public ITweet PublishTweetWithMedia(string text, byte[] media)
        {
            var parameters = new PublishTweetOptionalParameters();
            parameters.MediaBinaries.Add(media);

            return PublishTweet(text, parameters);
        }
Exemplo n.º 23
0
        public ITweet PublishTweetWithMedia(string text, long mediaId)
        {
            var parameters = new PublishTweetOptionalParameters();
            parameters.MediaIds.Add(mediaId);

            return PublishTweet(text, parameters);
        }
Exemplo n.º 24
0
        public ITweet PublishTweetInReplyTo(string text, ITweetIdentifier tweet)
        {
            var parameters = new PublishTweetOptionalParameters();
            parameters.InReplyToTweet = tweet;

            return PublishTweet(text, parameters);
        }
Exemplo n.º 25
0
        public ITweet PublishTweetInReplyTo(string text, long tweetId)
        {
            var parameters = new PublishTweetOptionalParameters();
            parameters.InReplyToTweetId = tweetId;

            return PublishTweet(text, parameters);
        }