Get all tweets in a given Geo area

Jan 24, 2014 at 10:01 PM
Edited Jan 24, 2014 at 10:05 PM
Hello Joe,

my goal is to get as many tweets as possible from a given area that are tweeted, in a live way. Sounds like "stream all tweets from this place while web application running", but you wrote in an article that ApplicationOnlyAuthorizer does not let you stream. (do i need a diffirent authorizer?).

Reading your tutorials and guides i 've concluded that i need a search query with a given geocode in a while(true) loop so it would feel like stream. The problem with this approach is that search queries have to have a query filter which i don't want, because i want ALL tweets no matter what their tweet text.

here is my code
protected async void RefreshButton_Click(object sender, EventArgs e)
{
         var auth = new ApplicationOnlyAuthorizer
            {
                CredentialStore = new InMemoryCredentialStore
                {
                    ConsumerKey = ConfigurationManager.AppSettings["ConsumerKey"],
                    ConsumerSecret = ConfigurationManager.AppSettings["ConsumerSecret"]
                    
                }
            };

            await auth.AuthorizeAsync();

            var twitterCtx = new TwitterContext(auth);

            var searchResponse =
                await
                (from search in twitterCtx.Search
                 where search.Type == SearchType.Search &&
                       search.GeoCode == "37.770715,22.102776,320km" &&
                       search.Query == "__???????????????????????????????__" &&
                       search.SearchLanguage == "en" &&
                       search.Count == 100
                 select search)
                .SingleOrDefaultAsync();
            int i = 1;
            if (searchResponse != null && searchResponse.Statuses != null)
                searchResponse.Statuses.ForEach(tweet =>
                    Response.Write(
                        "<b>Tweet:</b> " + i++ +
                        "&nbsp;&nbsp;<b>User:</b> " + tweet.User.ScreenNameResponse +
                        "&nbsp;&nbsp;<b>Text:</b> " + tweet.Text +
                        "&nbsp;&nbsp;<b>Coords:</b> " + tweet.Coordinates.Latitude + tweet.Coordinates.Longitude +
                        "&nbsp;&nbsp;<b>Created at:</b> " + tweet.CreatedAt +
                        "<br/>"
                        ));
        }
}
So, any ideas how can i "bypass" the search.Query to not filter my tweets ?

An other question is, will i get blocked from tweeter if i do an infinite loop on the search query?
Jan 24, 2014 at 10:30 PM
Hi,

You can try using the SingleUserAuthorizer. This is a snippet form the console demo:
var auth = new SingleUserAuthorizer
{
    CredentialStore = new SingleUserInMemoryCredentialStore
    {
        ConsumerKey = ConfigurationManager.AppSettings["consumerKey"],
        ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"],
        AccessToken = ConfigurationManager.AppSettings["accessToken"],
        AccessTokenSecret = ConfigurationManager.AppSettings["accessTokenSecret"]
    }
};
And than you can use the Filtered Statuses Stream to filter based on location.
Marked as answer by Fatha on 1/25/2014 at 2:59 PM
Jul 24, 2014 at 10:52 AM
Hi,
I need also to search by geocode only... and the first solution that I found to skip the required query text parameter is to use it with the geocode information, like this:
var searchResponse =
    await
    (from search in twitterCtx.Search
     where search.Type == SearchType.Search &&
           search.Query == "geocode:37.770715,22.102776,320km" &&
           search.SearchLanguage == "en" &&
           search.Count == 100
     select search)
    .SingleOrDefaultAsync();
I think that in the next updates will be useful skip the query param check when the geocode is not null.
Feb 9, 2015 at 5:52 AM
Hi kfmarcov,

above solution works for me, but I have requirement to pass some filter in Query parameter and also geo code

if I do like
 var geocode = "12.970057, 77.580128, 100km";
            var searchResponse =
               await
               (from search in twitterContext.Search
                where search.Type == SearchType.Search &&
                      search.Query == "\"Bengaluru\""                     
                     && search.GeoCode == geocode
                     && search.Count == 10
                      && search.Locale == "en"
                select search)
               .SingleOrDefaultAsync();
No output is returned, Do we have any update on this issue?