Ejemplo n.º 1
0
        public async Task StartStreaming(int sampleSize)
        {
            Log.Information($"TwitterStreamService.StartStreaming {DateTime.Now:hh:mm:ss}");
            await cache.ResetCache(sampleSize);

            try
            {
                SampledStreamService streamService = new SampledStreamService(oAuthInfo, this.appSettings.BearerToken);
                streamService.DataReceivedEvent += StreamService_DataReceivedEvent;
                streamService.StartStream("https://api.twitter.com/2/tweets/sample/stream?expansions=author_id,attachments.media_keys&tweet.fields=public_metrics,attachments,context_annotations,entities&media.fields=duration_ms,height,media_key,preview_image_url,type,url,width,public_metrics", sampleSize, 1);
            }
            catch (Exception)
            {
                throw;
            }
        }
        static void Main(string[] args)
        {
            /*TwitinfoModel ti = new TwitinfoModel
             * {
             *  TwitJson = "sample twitter info"
             * };*/

            //List<SampledStream> lstSampledStream = new List<SampledStream>();
            string _ConsumerKey       = ConfigurationManager.AppSettings.Get("ConsumerKey");
            string _ConsumerSecret    = ConfigurationManager.AppSettings.Get("ConsumerSecret");
            string _AccessToken       = ConfigurationManager.AppSettings.Get("AccessToken");
            string _AccessTokenSecret = ConfigurationManager.AppSettings.Get("AccessTokenSecret");
            string _BearerToken       = ConfigurationManager.AppSettings.Get("BearerToken");

            //// Connect to emitter
            //var emitter = Connection.Establish();

            // Set up your credentials
            OAuthInfo oAuthInfo = new OAuthInfo
            {
                AccessSecret   = _AccessTokenSecret,
                AccessToken    = _AccessToken,
                ConsumerSecret = _ConsumerSecret,
                ConsumerKey    = _ConsumerKey,
                BearerToken    = _BearerToken
            };


            // Sampled Stream Service Test
            SampledStreamService streamService = new SampledStreamService(oAuthInfo);

            streamService.DataReceivedEvent += StreamService_DataReceivedEvent;
            streamService.StartStream("https://api.twitter.com/2/tweets/sample/stream?expansions=attachments.poll_ids,attachments.media_keys,author_id,entities.mentions.username,geo.place_id,in_reply_to_user_id,referenced_tweets.id,referenced_tweets.id.author_id", 100, 5);

            //streamService.StartStream("https://api.twitter.com/2/tweets/sample/stream", 100, 1);

            //Console.WriteLine("Twitter Analytics");
            /*Console.WriteLine($"{ ti.TwitJson }");*/
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            string _ConsumerKey       = ConfigurationManager.AppSettings.Get("ConsumerKey");
            string _ConsumerSecret    = ConfigurationManager.AppSettings.Get("ConsumerSecret");
            string _AccessToken       = ConfigurationManager.AppSettings.Get("AccessToken");
            string _AccessTokenSecret = ConfigurationManager.AppSettings.Get("AccessTokenSecret");

            OAuthInfo oAuthInfo = new OAuthInfo
            {
                AccessSecret   = _AccessTokenSecret,
                AccessToken    = _AccessToken,
                ConsumerSecret = _ConsumerSecret,
                ConsumerKey    = _ConsumerKey
            };

            HideReplyService hideRepliesService = new HideReplyService(oAuthInfo);
            HideReplyModel   model = hideRepliesService.HideReply("1296341968176451585");

            // Sampled Stream Service Test
            SampledStreamService streamService = new SampledStreamService(oAuthInfo);

            streamService.DataReceivedEvent += StreamService_DataReceivedEvent;
            streamService.StartStream("https://api.twitter.com/2/tweets/sample/stream?expansions=attachments.poll_ids,attachments.media_keys,author_id,entities.mentions.username,geo.place_id,in_reply_to_user_id,referenced_tweets.id,referenced_tweets.id.author_id", 100, 5);

            // Recent Search
            RecentSearchService searchService = new RecentSearchService(oAuthInfo);

            List <RecentSearchResultsModel> resultsModels = searchService.SearchTweets("iphone", 100, 3);

            // Tweet(s)
            TweetService tweetsService = new TweetService(oAuthInfo);
            TweetModel   tweetModel    = tweetsService.GetTweet("1293779846691270658");

            List <string> tids = new List <string>();

            tids.Add("1293779846691270658"); // social opinion tweet
            tids.Add("1293779846691270658"); // social opinion tweet
            TweetsModel tweetModels = tweetsService.GetTweets(tids);

            // User(s)
            UserService userService = new UserService(oAuthInfo);
            UserModel   userModel   = userService.GetUser("socialopinions");

            List <string> users = new List <string>();

            users.Add("jamie_maguire1");
            users.Add("socialopinions");
            UsersModel usersResults = userService.GetUsers(users);

            // Metrics
            List <string> ids = new List <string>();

            ids.Add("1258736674844094465"); // social opinion tweet
            TweetMetricsService     service      = new TweetMetricsService(oAuthInfo);
            List <TweetMetricModel> metricModels = service.GetTweetMetrics(ids);

            // testing Filtered Stream
            FilteredStreamService filteredStreamService = new FilteredStreamService(oAuthInfo);

            List <FilteredStreamRule> rules = filteredStreamService.CreateRule(
                new MatchingRule {
                tag = "testing #iPhone", Value = "#iphone"
            });

            filteredStreamService.DataReceivedEvent += FilteredStreamService_DataReceivedEvent;
            filteredStreamService.StartStream("https://api.twitter.com/2/tweets/search/stream?tweet.fields=attachments,author_id,context_annotations,conversation_id,created_at,entities,geo,id,in_reply_to_user_id,lang,public_metrics,possibly_sensitive,referenced_tweets,source,text,withheld&expansions=author_id&user.fields=created_at,description,entities,id,location,name,pinned_tweet_id,profile_image_url,protected,public_metrics,url,username,verified,withheld", 10, 5);
        }