DarkNIcatcher
DarkNIcatcher

Reputation: 1

How can i search tweets by word and show it in my project using c# and tweetinvi

im making project that find tweet by specific words and analyze it.Im new in C# and i found on corner of Internet that i can use TweetInvi 5.0 Nuget package to deal with Twitter Api v2.0,I've written code but it dont work,I need your help mates.Here is my code.It returns nothing.

static void Main(string[] args)
    {
        string txt = "Bitcoin";
        SearchTweet(txt);
     
    }

    static async void SearchTweet(string txt)
    {
        TwitterClient twitterClient = new TwitterClient(APIKey,APISecret,AccessToken,accessTokenSecret);
        var searchParam = new SearchTweetsParameters(txt) {
            Lang = LanguageFilter.English,
            SearchType = SearchResultType.Popular,
        };
        IEnumerable<ITweet> searchResponse = (IEnumerable<ITweet>)await twitterClient.SearchV2.SearchTweetsAsync(txt);

        foreach ( var item in searchResponse)
        {
            Console.WriteLine(item.Text);
        }

I debugged it and its stopping working in this line.

 IEnumerable<ITweet> searchResponse = (IEnumerable<ITweet>)await twitterClient.SearchV2.SearchTweetsAsync(txt);

Upvotes: 0

Views: 325

Answers (1)

Ashok Garg
Ashok Garg

Reputation: 73

You are calling async function SearchTweet from function Main. The Main function exits and unloads the application without letting your SearchTweet function to complete. Add Console.ReadLine() in your Main function as under:

SearchTweet(txt);
Console.ReadLine();

Upvotes: 0

Related Questions