static void Main(string[] args)
        {
            TwangManSays("********************************************");
            TwangManSays("*             HANG THE TWANG               *");
            TwangManSays("********************************************");
            CurrentGames = new Dictionary<long, TwitterThread>();
            tweetsToSend = new ConcurrentQueue<SendArgs>();

           
            TwitterSender = new Task(DoWork);
            TwitterSender.Start();

            _sendService = new TwitterService(Authentication.ConsumerKey, Authentication.ConsumerSecret);
            _sendService.AuthenticateWith(Authentication.AccessToken, Authentication.AccessTokenSecret);

            _service = new TwitterService(Authentication.ConsumerKey, Authentication.ConsumerSecret);
            _service.AuthenticateWith(Authentication.AccessToken, Authentication.AccessTokenSecret);

            TwitterListener = new Task(Listen);
            TwitterListener.Start();


            Console.ReadLine();
            _service.CancelStreaming();
        }
        static void Main(string[] args)
        {
            string _consumerKey = "JXTOavtgUIN3ucDNRX3qsG5HM",
                _consumerSecret = "zf7szYPlnz4RG4utTsHnQRrreye4aNDoj8SNw6yiuklG9roDaj",
                _accessToken = "65598981-Hbx6HVVi1prAkW1MkzhBEw8oX2vNTti1UMK4BAAiS",
                _accessTokenSecret = "yuQWecLhU5GqBUgdhysiJm7hbBGLCnmTNEInZvu5xOiiF";
            var service1 = new TwitterService(_consumerKey, _consumerSecret);
            service1.AuthenticateWith(_accessToken, _accessTokenSecret);

            var block = new AutoResetEvent(false);
            TwitterStatus[] searchResult = new TwitterStatus[0];

            service1.Search(new SearchOptions() { Q = ":)", Count = 20, IncludeEntities = true, Lang = "en" }, (result, respone) =>
            {
                Console.WriteLine("On going...");
                HttpStatusCode code = respone.StatusCode;

                if (code == HttpStatusCode.OK)
                {
                    searchResult = new TwitterStatus[result.Statuses.Count()];
                    result.Statuses.ToList().CopyTo(searchResult);
                    block.Set();
                }
            });

            //TwitterRateLimitStatus rate = service1.Response.RateLimitStatus;
            //Console.WriteLine("You have used " + rate.RemainingHits + " out of your " + rate.HourlyLimit);

            Console.WriteLine("Out going...");
            block.WaitOne();
            service1.CancelStreaming();
            if (searchResult.Count() > 0)
            {
                WebClient webClient = new WebClient();
                StreamWriter writer = new StreamWriter("out.txt");
                for (int i = 0; i < searchResult.Count(); i++){
                    var photo = searchResult[i].Entities.Media.FirstOrDefault(m => m.MediaType == TwitterMediaType.Photo);
                    string attachedPhoto = "-";
                    if (photo != null)
                    {
                        attachedPhoto = "O";
                        webClient.DownloadFile(photo.MediaUrl, searchResult[i].Id + ".jpg");
                    }
                    string s = searchResult[i].Id + "\t" + attachedPhoto + "\t" + searchResult[i].User.ScreenName + "\t" + searchResult[i].Text;
                    writer.WriteLine(s);
                }
                writer.Close();
            }
            Console.WriteLine("Finish");
        }
Beispiel #3
0
        public static void ListenOnUserStream(TwitterService service)
        {
            service.AuthenticateWith(accessToken, accessTokenSecret);

            Console.WriteLine("Starting Listen");

            service.StreamUser((streamEvent, response) =>
            {
                Console.WriteLine(streamEvent.RawSource);
            });

            Console.ReadLine();

            service.CancelStreaming();
            Console.WriteLine("Ending Listen");
        }
Beispiel #4
0
        public void CanGetUserStream()
        {
            var service = new TwitterService(consumerKey, consumerSecret);
            service.AuthenticateWith(accessToken, accessTokenSecret);

            var block = new AutoResetEvent(false);

            Console.WriteLine("About to start listening on stream");

            Task.Factory.StartNew(() => block.Set());

            //			service.StreamUser((streamEvent, response) =>
            //            {
            //				Console.WriteLine(streamEvent.RawSource);
            //				block.Set();
            //			});

            Console.WriteLine("Waiting for events");
            block.WaitOne();

            service.CancelStreaming();
        }