static async void SendTweetWithSinglePicture()
        {
            var auth = new SingleUserAuthorizer
            {
                CredentialStore = new SingleUserInMemoryCredentialStore
                {
                    ConsumerKey = "your consumer key",
                    ConsumerSecret = "your consumer secret",
                    AccessToken = "your access token",
                    AccessTokenSecret = "your access token secret"
                }
            };

            var context = new TwitterContext(auth);

            var uploadedMedia = await context.UploadMediaAsync(File.ReadAllBytes(@"c:\path\to\image.jpg"));
            var mediaIds = new List<ulong> { uploadedMedia.MediaID };

            await context.TweetAsync(
                "Hello World! I am testing @dougvdotcom's #LinqToTwitter demo, at " +
                "https://www.dougv.com/2015/08/posting-twitter-status-updates-tweets-with-linqtotwitter-and-net-part-3-media-tweets",
                mediaIds
            );
        }
Beispiel #2
0
        public static async void PostTwitter()
        {
            string pl;

            //var auth = AuthorizeTwitter();

            var auth = AuthorizeTwitterWithToken();



            var ctx = new TwitterContext(auth);

            //var new Media
            //    {
            //        Data = Utilities.GetFileBytes(replaceThisWithYourImageLocation),
            //        FileName = "200xColor_2.png",
            //        ContentType = MediaContentType.Png
            //    };

            //await ctx.TweetWithMediaAsync("Testing from Application. Posting Image", false, ReadImageFile(Path.GetFullPath("image.png")));

            await ctx.TweetAsync("Testing from Application. Second Tweet!");
            //var twitterCtx = new TwitterContext(auth);

            await TwitterParameters(auth);
        }
        async void TweetButton_Click(object sender, RoutedEventArgs e)
        {
            var twitterCtx = new TwitterContext(SharedState.Authorizer);

            Status tweet = await twitterCtx.TweetAsync(TweetTextBox.Text);

            await new MessageDialog(tweet.Text, "Tweet Sent").ShowAsync();
        }
Beispiel #4
0
        public static async void SendTweet(MvcAuthorizer auth, string message)
        {
            
            var ctx = new TwitterContext(auth);
            var context = new TwitterContext(auth);

            await context.TweetAsync(
                message
            );
        }
Beispiel #5
0
        public static async void ReTweet(MvcAuthorizer auth, int ID)
        {

            var ctx = new TwitterContext(auth);
            var context = new TwitterContext(auth);

            await context.TweetAsync(
                ID.ToString()
            );
        }
Beispiel #6
0
        static async Task AsyncMain()
        {
            // Get repositories
            string[] repos = ConfigurationManager.AppSettings["Repositories"]
                .Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(x => x.Trim())
                .ToArray();

            // Get excluded users
            string[] excludedUsers = ConfigurationManager.AppSettings["ExcludedUsers"]
                .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(x => x.Trim())
                .ToArray();

            // Authorize to GitHub
            string token = ConfigurationManager.AppSettings["GitHubToken"];
            GitHubClient github = new GitHubClient(new ProductHeaderValue("IssueTweeter"))
            {
                Credentials = new Credentials(token)
            };

            // Get issues for each repo
            DateTimeOffset since = DateTimeOffset.UtcNow.AddHours(-1);
            List<Task<List<KeyValuePair<string, string>>>> issuesTasks = repos.Select(x => GetIssues(github, x, since, excludedUsers)).ToList();
            await Task.WhenAll(issuesTasks);

            // Authorize to Twitter
            SingleUserAuthorizer twitterAuth = new SingleUserAuthorizer
            {
                CredentialStore = new SingleUserInMemoryCredentialStore
                {
                    ConsumerKey = ConfigurationManager.AppSettings["TwitterConsumerKey"],
                    ConsumerSecret = ConfigurationManager.AppSettings["TwitterConsumerSecret"],
                    AccessToken = ConfigurationManager.AppSettings["TwitterAccessToken"],
                    AccessTokenSecret = ConfigurationManager.AppSettings["TwitterAccessTokenSecret"]
                }
            };
            TwitterContext twitterContext = new TwitterContext(twitterAuth);

            // Get recent tweets
            string twitterUser = ConfigurationManager.AppSettings["TwitterUser"];
            List<Status> timeline = await twitterContext.Status
                .Where(x => x.Type == StatusType.User && x.ScreenName == twitterUser && x.Count == 200)
                .ToListAsync();

            // Aggregate and eliminate issues already tweeted
            List<string> tweets = issuesTasks
                .SelectMany(x => x.Result.Where(i => !timeline.Any(t => t.Text.Contains(i.Key))).Select(i => i.Value))
                .ToList();

            // Send tweets
            List<Task<Status>> tweetTasks = tweets.Select(x => twitterContext.TweetAsync(x)).ToList();
            await Task.WhenAll(tweetTasks);
        }
        protected async void PostUpdateButton_Click(object sender, EventArgs e)
        {
            var auth = new AspNetAuthorizer
            {
                CredentialStore = new SessionStateCredentialStore(),
                GoToTwitterAuthorization = twitterUrl => { }
            };

            var ctx = new TwitterContext(auth);

            await ctx.TweetAsync(UpdateTextBox.Text);

            SuccessLabel.Visible = true;
        }
Beispiel #8
0
		public async Task<bool> TweetAsync(string content)
		{
			var tweetContent = CheckContent(content);

			try
			{
				using (var context = new TwitterContext(_selfAuthorizer))
				{
					await context.TweetAsync(content);
					return true;
				}
			}
			catch (TwitterQueryException ex) when (ex.StatusCode == HttpStatusCode.Forbidden) // In case of duplicate
			{
				return false;
			}
		}
        private void nouveauTweetBouton_Click(object sender, EventArgs e)
        {
            var twitterContext = new TwitterContext(authorizer);

            nouveauTweetFenetre nt = new nouveauTweetFenetre();

            if (nt.ShowDialog() == DialogResult.OK)
            {

                if (nt.Tweet.Length > 0)
                {
                    twitterContext.TweetAsync(nt.Tweet);
                    MessageBox.Show("Le tweet est publié");
                }

                recupererTweets();
            }
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            Task.Run(async () =>
            {

                AppSettingsReader cfgReader = new AppSettingsReader();

                string _UseProxy = cfgReader.GetValue("UseProxy", typeof(string)).ToString();

                var auth = new SingleUserAuthorizer
                {
                    CredentialStore = new SingleUserInMemoryCredentialStore
                    {
                        ConsumerKey = cfgReader.GetValue("ConsumerKey", typeof(string)).ToString(),
                        ConsumerSecret = cfgReader.GetValue("ConsumerSecret", typeof(string)).ToString(),
                        AccessToken = cfgReader.GetValue("AccessToken", typeof(string)).ToString(),
                        AccessTokenSecret = cfgReader.GetValue("AccessSecret", typeof(string)).ToString()
                    }
                };

                if (_UseProxy.Equals("1"))
                {
                    auth.Proxy = new WebProxy(cfgReader.GetValue("ProxyAddress", typeof(string)).ToString());
                    auth.Proxy.Credentials = new NetworkCredential(
                        cfgReader.GetValue("ProxyUser", typeof(string)).ToString(),
                        cfgReader.GetValue("ProxyPass", typeof(string)).ToString());
                }

                var twitterContext = new TwitterContext(auth);

                string _teste = "Tweet sent via LinqToTwitter";

                var tweet = await twitterContext.TweetAsync(_teste);

                if (tweet != null)
                {
                    Console.WriteLine("Status: {0}", tweet.StatusID.ToString());
                }

            }).Wait();

            Console.ReadLine();
        }
        public async Task<ActionResult> TweetAsync(SendTweetViewModel tweet)
        {
            var auth = new MvcAuthorizer
            {
                CredentialStore = new SessionStateCredentialStore()
            };

            var ctx = new TwitterContext(auth);

            Status responseTweet = await ctx.TweetAsync(tweet.Text);

            var responseTweetVM = new SendTweetViewModel
            {
                Text = "Testing async LINQ to Twitter in MVC - " + DateTime.Now.ToString(),
                Response = "Tweet successful! Response from Twitter: " + responseTweet.Text
            };

            return View(responseTweetVM);
        }
        async void TweetButton_Click(object sender, RoutedEventArgs e)
        {
            IAuthorizer auth = SharedState.Authorizer;

            var twitterCtx = new TwitterContext(auth);

            decimal latitude = 37.78215m;
            decimal longitude = -122.40060m;

            Status tweet = await twitterCtx.TweetAsync(TweetTextBox.Text, latitude, longitude);

            MessageBox.Show(
                "User: "******", Posted Status: " + tweet.Text,
                "Update Successfully Posted.",
                MessageBoxButton.OK);

            TweetTextBox.Text = "Windows Phone Test, " + DateTime.Now.ToString() + " #linq2twitter";
        }
        static async void SendTweet()
        {
            var auth = new SingleUserAuthorizer
            {
                CredentialStore = new SingleUserInMemoryCredentialStore
                {
                    ConsumerKey = "your consumer key",
                    ConsumerSecret = "your consumer secret",
                    AccessToken = "your access token",
                    AccessTokenSecret = "your access token secret"
                }
            };

            var context = new TwitterContext(auth);

            await context.TweetAsync(
                "Hello World! I am testing @dougvdotcom's #LinqToTwitter demo, at " +
                "https://www.dougv.com/2015/08/posting-status-updates-to-twitter-via-linqtotwitter-part-2-plain-text-tweets"
            );
        }
        private async void TweetButton_Click(object sender, RoutedEventArgs e)
        {
            var authorizer = new UniversalAuthorizer
            {
                CredentialStore = new InMemoryCredentialStore
                {
                    ConsumerKey = "",
                    ConsumerSecret = ""
                }
            };

            await authorizer.AuthorizeAsync();
            var ctx = new TwitterContext(authorizer);

            string userInput = tweetText.Text;
            Status tweet = await ctx.TweetAsync(userInput);

            ResponseTextBlock.Text = tweet.Text;

            await new MessageDialog("You Tweeted: " + tweet.Text, "Success!").ShowAsync();
        }
        public async Task<ActionResult> PostTweet(string tweetText = "")
        {
            MvcAuthorizer auth = new MvcAuthorizer
            {
                CredentialStore = new SessionStateCredentialStore()
            };

            // do OAuth if the token is null
            if (auth.CredentialStore.OAuthToken == null)
            {
                return RedirectToAction("BeginAsync", "OAuth", new { returnUrl = Request.Url });
            }

            Status postedTweet;
            ulong postedTweetStatusId = 0;
            if (!string.IsNullOrEmpty(tweetText))
            {
                var twitterCtx = new TwitterContext(auth);

                postedTweet = await twitterCtx.TweetAsync(tweetText);

                postedTweetStatusId = postedTweet.StatusID;
            }
            else
            {
                postedTweet = null;
            }

            var viewModel = new PostTweetViewModel()
            {
                TweetText = tweetText,
                PostedTweet = postedTweet,
                PostedTweetStatusId = postedTweetStatusId
            };

            return View(viewModel);
        }
        public static void Send(string msg)
        {
            TwitterContext context = new TwitterContext(new MvcAuthorizer()
            {
                CredentialStore = new LinqToTwitter.InMemoryCredentialStore()
                {
                    OAuthTokenSecret = ConfigurationManager.AppSettings["OAuthTokenSecret"],
                    ConsumerKey = ConfigurationManager.AppSettings["ConsumerKey"],
                    ConsumerSecret = ConfigurationManager.AppSettings["ConsumerSecret"],
                    OAuthToken = ConfigurationManager.AppSettings["OAuthToken"]
                }
            });

            var tweetTask = context.TweetAsync(msg);
            tweetTask.Wait();
            if (!tweetTask.IsFaulted)
            {
                var status = tweetTask.Result;
                if (status != null)
                {
                    context.DeleteTweetAsync(status.StatusID).Wait();
                }
            }
        }
Beispiel #17
0
        static async Task UploadVideoAsync(TwitterContext twitterCtx)
        {
            string status =
                "Testing video upload tweet #Linq2Twitter £ " +
                DateTime.Now.ToString(CultureInfo.InvariantCulture);

            Media media = await twitterCtx.UploadMediaAsync(File.ReadAllBytes(@"..\..\images\SampleVideo.mp4"), "video/mp4");

            Status tweet = await twitterCtx.TweetAsync(status, new ulong[] { media.MediaID });

            if (tweet != null)
                Console.WriteLine("Tweet sent: " + tweet.Text);
        }
Beispiel #18
0
        static async Task UploadMultipleImagesAsync(TwitterContext twitterCtx)
        {
            var additionalOwners = new List<ulong> { 3265644348, 15411837 };
            string status = 
                "Testing multi-image tweet #Linq2Twitter £ " + 
                DateTime.Now.ToString(CultureInfo.InvariantCulture);

            var imageUploadTasks = 
                new List<Task<Media>> 
                {
                    twitterCtx.UploadMediaAsync(File.ReadAllBytes(@"..\..\images\200xColor_2.png"), "image/png", additionalOwners),
                    twitterCtx.UploadMediaAsync(File.ReadAllBytes(@"..\..\images\WP_000003.jpg"), "image/jpg"),
                    twitterCtx.UploadMediaAsync(File.ReadAllBytes(@"..\..\images\13903749474_86bd1290de_o.jpg"), "image/jpg"),
                };

            await Task.WhenAll(imageUploadTasks);

            List<ulong> mediaIds =
                (from tsk in imageUploadTasks
                 select tsk.Result.MediaID)
                .ToList();

            Status tweet = await twitterCtx.TweetAsync(status, mediaIds);

            if (tweet != null)
                Console.WriteLine("Tweet sent: " + tweet.Text);
        }
Beispiel #19
0
        static async Task TweetAsync(TwitterContext twitterCtx)
        {
            Console.Write("Enter your status update: ");
            string status = Console.ReadLine();

            Console.WriteLine("\nStatus being sent: \n\n\"{0}\"", status);
            Console.Write("\nDo you want to update your status? (y or n): ");
            string confirm = Console.ReadLine();

            if (confirm.ToUpper() == "N")
            {
                Console.WriteLine("\nThis status is *not* being sent.");
            }
            else if (confirm.ToUpper() == "Y")
            {
                Console.WriteLine("\nPress any key to post tweet...\n");
                Console.ReadKey(true);

                Status tweet = await twitterCtx.TweetAsync(status);

                if (tweet != null)
                    Console.WriteLine(
                        "Status returned: " +
                        "(" + tweet.StatusID + ")" +
                        tweet.User.Name + ", " +
                        tweet.Text + "\n");
            }
            else
            {
                Console.WriteLine("Not a valid entry.");
            }
        }
        static async void SendTweetWithMultiplePictures()
        {
            var auth = new SingleUserAuthorizer
            {
                CredentialStore = new SingleUserInMemoryCredentialStore
                {
                    ConsumerKey = "your consumer key",
                    ConsumerSecret = "your consumer secret",
                    AccessToken = "your access token",
                    AccessTokenSecret = "your access token secret"
                }
            };

            var context = new TwitterContext(auth);

            var imageUploadTasks =
                new List<Task<Media>>
                {
                    context.UploadMediaAsync(File.ReadAllBytes(@"c:\path\to\image1.jpg")),
                    context.UploadMediaAsync(File.ReadAllBytes(@"c:\path\to\image2.png")),
                    context.UploadMediaAsync(File.ReadAllBytes(@"c:\path\to\image3.jpg"))
                };
            await Task.WhenAll(imageUploadTasks);
            
            var mediaIds =
                (from tsk in imageUploadTasks
                 select tsk.Result.MediaID)
                .ToList();

            await context.TweetAsync(
                "Photos of Acadia National Park by Kim Seng https://www.flickr.com/photos/captainkimo/ #LinqToTwitter",
                mediaIds
            );
        }
Beispiel #21
0
        public static async Task<string> PublishTweet(string userName, DateTime time, string template, TwitterContext context)
        {
            try
            {
                string usernamePH = "{username}";
                string timePH = "{time}";
                var message = template
                    .Replace(usernamePH, "@" + userName)
                    .Replace(timePH, DateTime.UtcNow.ToLongTimeString());
                    //.Replace(timePH, time.AddHours(-6).ToLongTimeString());

                if (message.Length <= 140)
                {
                    var tweet = await context.TweetAsync(message);

                    Logger.Log("Published tweet: " + message, "info");

                    Thread.Sleep(100);                    
                    //Task.Delay(1000);
                }
                else
                {
                    Logger.Log("tweet too long", "warning");

                    message = message.Remove(140);

                    var tweet = await context.TweetAsync(message);

                    Thread.Sleep(100);    
                }
                
            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString(), "error");
                return (ex.ToString());
            }
            return ("");
        }
Beispiel #22
0
 private static void statusUpdate(String tweetText, PinAuthorizer auth)
 {
     using (var twitter = new TwitterContext(auth))
     {
         var tweet = twitter.TweetAsync(tweetText);
     }
 }
Beispiel #23
0
        public Feed PostFeed(FeedModel model)
        {
            var user = repository.AsQueryable<Sociopath.DataEntities.Entities.User>().FirstOrDefault(x => x.Id == model.UserId);
            if (user == null)
            {
                return null;
            }

            var auth = new SingleUserAuthorizer
            {
                CredentialStore = new InMemoryCredentialStore
                {
                    ConsumerKey = ConsumerKey,
                    ConsumerSecret = ConsumerSecret,
                    OAuthToken = user.TwitterToken,
                    OAuthTokenSecret = user.TwitterSecret
                }
            };
            var twitterCtx = new TwitterContext(auth);

            //var twitterService = new TweetSharp.TwitterService(ConsumerKey, ConsumerSecret);
            //twitterService.AuthenticateWith(user.TwitterToken, user.TwitterSecret);
            //var tweet = twitterService.SendTweet(new SendTweetOptions { Status = model.Message });
            var tweet = twitterCtx.TweetAsync(model.Message).Result;
            var feed = new Feed { TwitterExternalId = tweet.StatusID.ToString(), Time = tweet.CreatedAt, Message = tweet.Text };
            return feed;
        }
 public static void SendTweet(string twitterUser, string status)
 {
     var twitterContext = new TwitterContext(TwitterHashtagMonitor.Authorizer);
     Task.FromResult(twitterContext.TweetAsync( status ));
 }