linvi / tweetinvi

Tweetinvi, an intuitive Twitter C# library for the REST and Stream API. It supports .NET, .NETCore, UAP (Xamarin)...
MIT License
1.01k stars 219 forks source link

Get latest tweet from one user #1153

Closed wibuf closed 2 years ago

wibuf commented 2 years ago

Hello, I'm new to using tweetinvi, and a beginner with c#. I've looked all over for awhile now to try and find some code to only pull the latest tweet from a user but haven't been able to find anything. Can someone assist me and provide some code if possible? I am able to pull a couple hundred tweets and get the text out, however they don't seem to be in order. Thanks

`var userTimeline = await userClient.Timelines.GetUserTimelineAsync("TweetinviApi");

        //Console.WriteLine("Retrieved " + page.Count() + page);

        foreach (var tweet in userTimeline)
        {
            int i = 0;
            if (i == 0){
                newestTweet = tweet.Text;
            }
            i++;
        }

        Console.WriteLine("We have now retrieved all the tweets!");
        Console.WriteLine("Newest Tweet: " + newestTweet);

        Console.ReadLine();`