예제 #1
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Get tweets!");

            var auth = new SingleUserAuthorizer
            {
                CredentialStore = new SingleUserInMemoryCredentialStore()
                {
                    ConsumerKey       = TwitterConsumerKey,
                    ConsumerSecret    = TwitterConsumerSecret,
                    AccessToken       = TwitterAccessToken,
                    AccessTokenSecret = TwitterAccessTokenSecret
                }
            };
            await auth.AuthorizeAsync();

            var twitterCtx = new TwitterContext(auth);
            var tweets     = await twitterCtx.GetTweets("cloudbrew");

            var credentials = new ApiKeyServiceClientCredentials(CognitiveServicesKey);
            var client      = new TextAnalyticsClient(credentials)
            {
                Endpoint = CognitiveServicesEndpoint
            };

            foreach (var t in tweets)
            {
                var sentiment = await client.SentimentAsync(t.FullText, t.Lang);

                Console.WriteLine($"ID   : {t.StatusID}");
                Console.WriteLine($"User : {t.User.Name}");
                Console.WriteLine($"Text : {t.FullText}");
                Console.WriteLine($"Score: {sentiment.Score:0.00}");

                if (sentiment.Score > 0.5)
                {
                    await twitterCtx.Retweet(t.StatusID);

                    Console.WriteLine("Retweeted!");
                }
            }
            Console.WriteLine("End");
            Console.ReadLine();
        }