简体   繁体   English

如何按单词搜索推文并使用 c# 和 tweetinvi 在我的项目中显示

[英]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. 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 ,我需要你的帮助队友。这是我的代码。它什么也不返回。

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);

You are calling async function SearchTweet from function Main.您正在从 function Main 调用异步 function SearchTweet。 The Main function exits and unloads the application without letting your SearchTweet function to complete.主 function 退出并卸载应用程序,而不让您的 SearchTweet function 完成。 Add Console.ReadLine() in your Main function as under:在 Main function 中添加 Console.ReadLine() 如下:

SearchTweet(txt);
Console.ReadLine();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM