Streaming only geotagged tweets (no keywords)

Nov 10, 2013 at 7:27 PM
Hi,
I was just wondering if it was possible to stream only tweets that are geo-tagged (regardless of where the location is), and without specifying a keyword parameter.

I have tried not adding any tracks and just adding a location, but when I do that, I get this error:

"The remote server returned an error: (406) Not Acceptable."

Which must be an invalid request response.

I cant find anywhere in your documentation where it speaks about location as a requirement in the request as opposed to searching based on a specific area (I'm not focusing on an exact location, I just only want to receive any geo-tagged tweets)

I am using the twitter recommended coordinates for specifying a location that means any geo-tagged tweets.

https://dev.twitter.com/docs/streaming-apis/parameters#locations

-180,-90,180,90

Like so:
  ICoordinates coordinates1 = new Coordinates(-180, -90);
  ICoordinates coordinates2 = new Coordinates(180, 90);
  ILocation location = new Location(coordinates1, coordinates2);
  ((FilteredStream)_stream).AddLocation(location);
However, when I specify both keywords to track and the location above, the stream works correctly.

Any ideas?

Thanks,
Justin
Nov 10, 2013 at 7:33 PM
Hi Justin,

Your idea was the right one, to insure that a tweet has a geo information, you need to add the extreme coordinates.
Your code should be working so I will have a look and let you know.

Linvi
Nov 10, 2013 at 7:42 PM
Hi again,

If you look in the Examplinvi project (provided in the source-code download), there already is an example like yours and it is working perfectly fine.
If you have a look in the output would you please send me a log which should looks like this :
POST : https://stream.twitter.com/1.1/statuses/filter.json?&locations=-180%2C-90%2C180%2C90
Regards,
Linvi
Nov 18, 2013 at 6:24 PM
Hi Linvi,
Strangely I am no longer getting the error message above. However when I now try and add both keywords filters and a location, I believe both get ignored as they number of tweets received grows massively. With two test terms I, on average get around 50 tweets a minute. When I then add the location using the code above that turns into thousands per minute. I also tested that it was not just ignoring the keywords by trying to print out the location coordinates for each tweet, but that throws a NullReferenceException so believe that both the keywords and location are being ignored.

Below is my wrapper class for your library:
    public class TwitterStreamClient : IStreamClient
    {
        private BaseTrackedStream _stream;
        private IToken _token;
        private bool _streamOpen = false;


        public TwitterStreamClient(IToken token, BaseTrackedStream stream, bool onlyGeoTagged = false, String[] filters = null)
        {
            _token = token;
            _stream = stream;

            if (filters != null)
            {
                AddFilters(filters);
            }

            if (stream.GetType() == typeof (FilteredStream) && onlyGeoTagged)
            {
                AddLocation();
            }
        }

        private void AddFilters(String[] filters)
        {
            for (int i = 0; i < filters.Length; ++i)
            {
                _stream.AddTrack(filters[i]);
            }
        }

        private void AddLocation()
        {
            ICoordinates coordinates1 = new Coordinates(-180, -90);
            ICoordinates coordinates2 = new Coordinates(180, 90);
            ILocation location = new Location(coordinates1, coordinates2);
            ((FilteredStream)_stream).AddLocation(location);
        }

        public void StartStream(Action<ITweet> action)
        {
            _stream.StartStream(_token, action);
            _streamOpen = true;

        }

        public void StartStream(Func<ITweet, bool> predicateFunc)
        {
            _stream.StartStream(_token, predicateFunc);
            _streamOpen = true;
        }

        public void StopStream()
        {
            _stream.StopStream();
            _streamOpen = false;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                // free managed resources
                if (_streamOpen)
                {
                    _stream.StopStream();
                    _stream = null;
                    _token = null;
                }
            }
        }
    }
And that is called from a test console application, like so:
 static void Main(string[] args)
        {

            string accessToken = ConfigurationManager.AppSettings["AccessToken"];
            string accessTokenSecret = ConfigurationManager.AppSettings["AccessTokenSecret"];
            string consumerKey = ConfigurationManager.AppSettings["ConsumerKey"];
            string consumerSecret = ConfigurationManager.AppSettings["ConsumerSecret"];


            IToken token = new Token(accessToken, accessTokenSecret, consumerKey, consumerSecret);

            String[] filters = new string[2]
            {
                "flu",
                "fluey"
            };

            TwitterStreamClient streamClient = new TwitterStreamClient(token, new FilteredStream(), true, filters);
            streamClient.StartStream(tweet =>  Console.WriteLine(tweet.Text + "\n\n"));
        }
Using this code, I get no exceptions but the tweets returned do not have the keywords I am filtering for, or have a location.

Thanks :)

Justin
Nov 18, 2013 at 6:53 PM
Hi there,

Tweetinvi provides 2 "modes" for the FilteredStream.
By default, StartStream is filtering that either condition is valid.

If you want to check that all the conditions are valid at the same time you need to use
stream.StartStreamMatchingAllConditions()
Hope this helps.
Linvi