Ejemplo n.º 1
0
        public SearchResultWithRateLimit Search(string queryTerm, int resultType, long sinceId, TwitterApp keys)
        {
            SearchOptions options = new SearchOptions
            {
                Q = System.Web.HttpUtility.UrlEncode(queryTerm),
                Count = 100,
                Lang = "en",
                Resulttype = (TwitterSearchResultType)resultType,
                SinceId = sinceId
            };

            var service = new TwitterService(keys.ConsumerKey, keys.ConsumerKeySecret);
            service.AuthenticateWith(keys.Token, keys.TokenSecret);
            var result = new SearchResultWithRateLimit();
            result.SearchResult = service.Search(options);
            result.RateLimitStatus = service.Response.RateLimitStatus;
            if (result.SearchResult.Statuses.Any())
            {
                result.LastId = result.SearchResult.Statuses.OrderByDescending(f => f.Id).FirstOrDefault().Id;
            }
            else
            {
                result.LastId = options.SinceId.Value;
            }

            return result;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            tweetsUserName = new List<PuzzleData>();
            TwitterService service = new TwitterService(consumerKey, consumerSecret);
            service.AuthenticateWith(accessToken, accessTokenSecret);

            var options = new SearchOptions { Q = "Brilliant @fredtrotter post about bitcoin, Wall Street, and cancer http://t.co/q9WZNA0cZR) Must read on \"malignant computation\"!", Count =30 };
            TwitterSearchResult tweets = service.Search(options);

            int i = 0;

            foreach (var tweet in tweets.Statuses)
            {
                authorUrl = tweet.RetweetedStatus.User.ProfileImageUrlHttps;
                if (authorUrl.Contains(".png") || authorUrl.Contains(".jpg") || authorUrl.Contains(".bmp"))
                {
                    authorUrl = authorUrl.Remove(authorUrl.Length - 11, 7);
                }
                else if (authorUrl.Contains(".jpeg"))
                {
                    authorUrl = authorUrl.Remove(authorUrl.Length - 12, 7);
                }
                i += 1;
                if (i > 10) break;

                tweetsUserName.Add(new PuzzleData() { followerCount = tweet.User.FollowersCount, profileImage = tweet.User.ProfileImageUrl, userId = tweet.User.Id });

            }
            tweetsUserName = tweetsUserName.OrderByDescending(x => x.followerCount).ToList();
        }
Ejemplo n.º 3
0
        private static void RunSearch(ITwitterService service, string searchTerm, IBus bus, IDocumentSession documentSession, IList <string> excludedTerms)
        {
            var options = new TweetSharp.SearchOptions {
                Q = searchTerm, Lang = "en", Resulttype = TwitterSearchResultType.Mixed
            };
            var results = service.Search(options);

            foreach (var result in results.Statuses)
            {
                var tweet = new Status
                {
                    Id         = Guid.NewGuid(),
                    TwitterId  = result.Id,
                    User       = result.User.ScreenName,
                    UserId     = result.User.Id,
                    Content    = result.Text,
                    Created    = result.CreatedDate,
                    SearchTerm = searchTerm
                };

                if (result.InReplyToStatusId.HasValue ||
                    documentSession.Query <Status>().Any(s => s.TwitterId == tweet.TwitterId) ||
                    excludedTerms.Any(t => result.Text.IndexOf(t, StringComparison.InvariantCultureIgnoreCase) > 0))
                {
                    return;
                }

                documentSession.Store(tweet);
                documentSession.SaveChanges();
                bus.Send(tweet);
            }
        }
Ejemplo n.º 4
0
        public SearchResultWithRateLimit Search(string query, long sinceid, TwitterApp keys)
        {
            var service = new TwitterService(keys.ConsumerKey, keys.ConsumerKeySecret);
            service.AuthenticateWith(keys.Token, keys.TokenSecret);
            var options = new SearchOptions
            {
                Q = System.Web.HttpUtility.UrlEncode(query),
                Count = 100,
                Lang = "en",
                Resulttype = TwitterSearchResultType.Mixed,
                SinceId = sinceid
            };

            // Geocode = new TwitterGeoLocationSearch(39.6456, -79.9433, 30, TwitterGeoLocationSearch.RadiusType.Mi),

            var result = new SearchResultWithRateLimit();
            result.SearchResult = service.Search(options);
            result.RateLimitStatus = service.Response.RateLimitStatus;
            if (result.SearchResult.Statuses.Any())
            {
                result.LastId = result.SearchResult.Statuses.OrderByDescending(f => f.Id).FirstOrDefault().Id;
            }
            else
            {
                result.LastId = sinceid;
            }

            return result;
        }
Ejemplo n.º 5
0
        public IQueryable<DisplayItem> GetSocialInfomation(string name)
        {
            IQueryable<DisplayItem> items = null;

            try
            {
                var twitterClientInfo = new TwitterClientInfo();
                twitterClientInfo.ConsumerKey = SettingsHelper.ConsumerKey;
                twitterClientInfo.ConsumerSecret = SettingsHelper.ConsumerSecret;

                var twitterService = new TwitterService(twitterClientInfo);
                twitterService.AuthenticateWith(SettingsHelper.AccessToken, SettingsHelper.AccessSecret);
                var searchOptions = new SearchOptions
                {
                    Q = name,
                };

                var searchResults = twitterService.Search(searchOptions);
                items = searchResults.Statuses.Select(x => ConvertToDataItem(x)).AsQueryable();
            }
            catch(Exception ex)
            {
                Logger.Error(ex);
            }

            return items;
        }
Ejemplo n.º 6
0
 public string GetTweetsFromPhrase(String phrase)
 {
     var service = new TwitterService(consumerKey, consumerSecret);
     service.AuthenticateWith(accessToken, accessTokenSecret);
     SearchOptions so = new SearchOptions();
     so.Q = phrase;
     so.Count = 100;
     var tweeting = service.Search(so);
     IEnumerable<TwitterStatus> returnValue = tweeting.Statuses;
     TweetsInst tweets = null;
     MulTweetInstance multweets = new MulTweetInstance();
     foreach (var twt in returnValue)
     {
         tweets = new TweetsInst();
         if (twt.Author.ScreenName != null)
         {
             tweets.author = twt.Author.ScreenName;
         }
         else { tweets.author = ""; }
         if (twt.Author.ProfileImageUrl != null)
         {
             tweets.UserImage = twt.Author.ProfileImageUrl;
         }
         else { tweets.UserImage = ""; }
         if (twt.User != null)
         {
             tweets.User_ID = Convert.ToString(twt.User.Id);
         }
         else { tweets.User_ID = null; }
         if (twt.Text != null)
         {
             tweets.tweet = twt.Text;
         }
         else { tweets.tweet = ""; }
         if (twt.Location != null)
         {
             tweets.latitude = Convert.ToString(twt.Location.Coordinates.Latitude);
         }
         else { tweets.latitude = ""; }
         if (twt.Location != null)
         {
             tweets.longitude = Convert.ToString(twt.Location.Coordinates.Longitude);
         }
         else { tweets.longitude = null; }
         if (twt.Place != null)
         {
             tweets.country = twt.Place.Country;
         }
         else { tweets.country = ""; }
         multweets.mulTweet.Add(tweets);
     }
     string output = JsonConvert.SerializeObject(multweets);
     return output;
 }
 public TwitterFactory SearchHashTag(string tag, int count)
 {
     SearchOptions opt = new SearchOptions();
     opt.Count = count;
     opt.Q = "#derbyscores";
     Result = Service.Search(opt);
     foreach (var item in Result.Statuses)
     {
         item.TextAsHtml = item.TextAsHtml.Replace("\n", "").Replace("\"", "");
     }
     return this;
 }
Ejemplo n.º 8
0
 private void searchTweets(string handle, string tag, long retweetCount = 0)
 {
     if (subscription != null)
     {
         subscription.Dispose();
     }
     SearchOptions options = new SearchOptions();
     options.Q = handle;
     options.Count = 10;
     options.Lang = "en";
     options.SinceId = lastTweetId;
     subscription =
     Observable.Interval(TimeSpan.FromSeconds(2))
         .Select(ticks => service.Search(options))
         //.SelectMany(response => response.Statuses)
         .SelectMany(response => response != null ? response.Statuses : new List<TwitterStatus>())
         .Where(x => x.HasHashTag(tag))
         .Where(x => x.RetweetCount > retweetCount)
         .Subscribe(
             status =>
             {
                 this.Invoke((MethodInvoker)delegate
                 {
                     options.SinceId = status.Id;
                     txtFeed.Text =
                         string.Format("\r\nTweet:{0}\r\nRetweetCount:{1}\r\n\r\n{2}",
                             status.Text, status.RetweetCount, txtFeed.Text);
                 });
             },
             ex =>
             {
                 this.Invoke((MethodInvoker)delegate
                 {
                     txtFeed.Text = ex.Message;
                 });
             },
             () =>
             {
                 this.Invoke((MethodInvoker)delegate
                 {
                     txtFeed.Text = "Done";
                 });
             }
         );
 }
Ejemplo n.º 9
0
        public SearchResultWithRateLimit Search(SearchOptions options, TwitterApp keys)
        {
            var service = new TwitterService(keys.ConsumerKey, keys.ConsumerKeySecret);
            service.AuthenticateWith(keys.Token, keys.TokenSecret);
            var result = new SearchResultWithRateLimit();
            result.SearchResult = service.Search(options);
            result.RateLimitStatus = service.Response.RateLimitStatus;
            if (result.SearchResult.Statuses.Any())
            {
                result.LastId = result.SearchResult.Statuses.OrderByDescending(f => f.Id).FirstOrDefault().Id;
            }
            else
            {
                result.LastId = options.SinceId.Value;
            }

            return result;
        }
Ejemplo n.º 10
0
        public void getPublicTweets()
        {
            SearchOptions searchOptions = new SearchOptions();

            searchOptions.Count = 2000;
            searchOptions.Locale = "-122.75,36.8,-121.75,37.8";
            //var twitterResults = _twitterService.Search(searchOptions);
            GeoSearchOptions geoSearch = new GeoSearchOptions();
            geoSearch.ContainedWithin = "-122.75,36.8,-121.75,37.8";
            //geoSearch.
            var cosas = _twitterService.GeoSearch(geoSearch);

            Console.WriteLine("Hola");
            //TwitterGeoLocation geoLocation = new TwitterGeoLocation();
            //geoLocation.Coordinates =
            //searchOptions.

            //_twitterService.Search();
        }
Ejemplo n.º 11
0
        public void Search()
        {
            var options = new SearchOptions { Q = "#peercast_yp -RT", IncludeEntities = true, SinceId = sinceId };
            var tweets = service.Search(options);
            if(service.Response.StatusCode == HttpStatusCode.BadRequest)
            {
                throw new Exception();
            }

            HashSet<string> idset = new HashSet<string>();
            var sb = new StringBuilder();
            var rb = new StringBuilder();

            foreach (var tweet in tweets.Statuses)
            {
                if (sinceId < tweet.Id)
                {
                    sinceId = tweet.Id;
                }

                rb.AppendLine(tweet.Text);
                
                Channel channel = new Channel();
                if (channel.Parse(tweet))
                {
                    if (idset.Add(channel.name))
                    {
                        channel.UrlParseWithAPI(channel.expandedurl);
                        sb.Append(channel.ToString()).Append("\n");
                    }
                }

                //Console.WriteLine("{0} says '{1}'", tweet.User.ScreenName, tweet.Text);
            }

            OnIndexTextEvent(sb.ToString(), rb.ToString());
        }
		public virtual IAsyncResult BeginSearch(SearchOptions options)
		{
			var q = options.Q;
			var geocode = options.Geocode;
			var lang = options.Lang;
			var locale = options.Locale;
			var resultType = options.Resulttype;
			var count = options.Count;
			var since_id = options.SinceId;
			var max_id = options.MaxId;
			var include_entities = options.IncludeEntities;
			var callback = options.Callback;
				

			return BeginWithHammock<TwitterSearchResult>(WebMethod.Get, "search/tweets", FormatAsString, "?q=", q, "&geocode=", geocode, "&lang=", lang, "&locale=", locale, "&result_type=", resultType, "&count=", count, "&since_id=", since_id, "&max_id=", max_id, "&include_entities=", include_entities, "&callback=", callback);
		}
		public virtual void Search(SearchOptions options, Action<TwitterSearchResult, TwitterResponse> action)
		{
			var q = options.Q;
			var geocode = options.Geocode;
			var lang = options.Lang;
			var locale = options.Locale;
			var resultType = options.Resulttype;
			var count = options.Count;
			var since_id = options.SinceId;
			var max_id = options.MaxId;
			var include_entities = options.IncludeEntities;
			var callback = options.Callback;
			
			WithHammock(action, "search/tweets", FormatAsString, "?q=", q, "&geocode=", geocode, "&lang=", lang, "&locale=", locale, "&result_type=", resultType, "&count=", count, "&since_id=", since_id, "&max_id=", max_id, "&include_entities=", include_entities, "&callback=", callback);
		}
		public virtual Task<TwitterAsyncResult<TwitterSearchResult>> SearchAsync(SearchOptions options)
		{
			var q = options.Q;
			var geocode = options.Geocode;
			var lang = options.Lang;
			var locale = options.Locale;
			var resultType = options.Resulttype;
			var count = options.Count;
			var since_id = options.SinceId;
			var max_id = options.MaxId;
			var include_entities = options.IncludeEntities;
			var callback = options.Callback;
			var until = options.Until;
			
			return WithHammockTask<TwitterSearchResult>(_client, "search/tweets", FormatAsString, "?q=", q, "&geocode=", geocode, "&lang=", lang, "&locale=", locale, "&result_type=", resultType, "&count=", count, "&since_id=", since_id, "&max_id=", max_id, "&include_entities=", include_entities, "&callback=", callback, "&until=", until);
		}
Ejemplo n.º 15
0
        private void btnAra_Click(object sender, EventArgs e)
        {
            int count = 0;
            lstTweets.Items.Clear();
            if (!String.IsNullOrEmpty(txtAra.Text))
            {
                if (rbtnHashtag.Checked)
                {
                    string aranan = "#" + txtAra.Text;
                   var AramaAyari = new SearchOptions
                   { Q = aranan, Count = 20, Lang ="tr"};
                   var Ara = servis.Search(AramaAyari);

                    /* for (int i = 0; i < 5; i++)
                     {
                         var statusTweets = (from tweet in twitterCtx.Status
                                             where tweet.Type == StatusType.User &&
                                             tweet.Count == 200 &&
                                             tweet.ScreenName == "username" &&
                                             tweet.Page == i
                                             select tweet)
                                             linqtosql
                      }*/
                    //twitter4j tweets more than 100

                    foreach (var i in Ara.Statuses)
                    {

                        count++;
                        //string s = i.Language;
                        var Tweets = String.Format("{0}: {1}. tweet: '{2}'",i.CreatedDate.AddHours(3), count, i.Text);
                        lstTweets.Items.Add(Tweets);

                    }

                    //txtspellcheck.Text += Tweets+"\n";
                    //fSpellCheck(txtspellcheck, label2);
                }

                else if (rbtnKelime.Checked)
                {
                    string aranan = txtAra.Text;
                    var AramaAyari = new SearchOptions { Q = aranan, Count = 20 };
                    var Ara = servis.Search(AramaAyari);
                    foreach (var i in Ara.Statuses)
                    {
                        count++;
                        var Tweets = String.Format("{0}. tweet: '{1}'", count, i.Text);
                        lstTweets.Items.Add(Tweets);

                    }
                }
                else
                {
                    MessageBox.Show("Ne ile arama yapacağınızı seçin lütfen", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Arayacağınız kelimeyi girin lütfen", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
		public virtual Task<TwitterResponse<TwitterSearchResult>> SearchAsync(SearchOptions options)
		{
			var q = options.Q;
			var geocode = options.Geocode;
			var lang = options.Lang;
			var locale = options.Locale;
			var resultType = options.Resulttype;
			var count = options.Count;
			var since_id = options.SinceId;
			var max_id = options.MaxId;
			var include_entities = options.IncludeEntities;
			var callback = options.Callback;
				
			
			return ExecuteRequest<TwitterSearchResult>("search/tweets", FormatAsString, "?q=", q, "&geocode=", geocode, "&lang=", lang, "&locale=", locale, "&result_type=", resultType, "&count=", count, "&since_id=", since_id, "&max_id=", max_id, "&include_entities=", include_entities, "&callback=", callback);
		}
        public void StartGettingQuestions()
        {
            SearchOptions searchOptions = new SearchOptions();
            searchOptions.Q = Properties.Settings.Default.twitterSearchTag;
            searchOptions.Count = 30;
            searchOptions.Resulttype = TwitterSearchResultType.Mixed;
            searchOptions.IncludeEntities = false;
            TwitterSearchResult tweets = service.Search(searchOptions);

            if (tweets != null)
            {
                foreach (var tweet in tweets.Statuses)
                {
                    string[] question = { tweet.Text, tweet.User.ScreenName };
                    QuestionsList.Add(question);
                }
            }
        }
Ejemplo n.º 18
0
        private void RetweetBaslat(DoWorkEventArgs e)
        {
            if (string.IsNullOrEmpty(txtHashTag.Text.Trim()))
            {
                MessageBox.Show("Anahtar Kelime giriniz!");
                return;
            }
            var searchOptions = new SearchOptions();
            searchOptions.Count = 100;
            searchOptions.IncludeEntities = true;
            searchOptions.Q = txtHashTag.Text.Trim();
            searchOptions.SinceId = GetLastId(searchOptions.Q);
            var tweets = service.Search(searchOptions);

            while (tweets.Statuses.Count() > 0 && retweetstarted)
            {
                tweets = service.Search(searchOptions);
                var tweetsStatutes = tweets.Statuses.OrderBy(t => t.Id).ToList();
                foreach (var tweet in tweetsStatutes)
                {
                    if (!retweetstarted)
                    {
                        e.Cancel = true;
                        break;
                    }
                    var status = service.Retweet(new RetweetOptions() { Id = tweet.Id });
                    WriteLastId(searchOptions.Q, tweet.Id);
                    Log(tweet.Text);
                    System.Threading.Thread.Sleep(2000);//twitter kızmasın
                }
                searchOptions.SinceId = tweetsStatutes.Last().Id;
            }
        }