简体   繁体   中英

Get Tweets Within Specific Location with TweetSharp

I'm trying to get tweets in a specific location. I'm using TweetSharp for that. I tried the following code:

// Pass your credentials to the service
            TwitterService service = new TwitterService("xx", "xx");


            // Step 4 - User authenticates using the Access Token
            service.AuthenticateWith("xx-xx", "xx");

            TwitterGeoLocationSearch geoSearch = new TwitterGeoLocationSearch(39.56, 32.52, 500, TwitterGeoLocationSearch.RadiusType.Km);

            //IEnumerable<TwitterStatus> mentions = service.ListTweetsOnHomeTimeline(new ListTweetsOnHomeTimelineOptions());

            var tweets = service.Search(new SearchOptions() { Q = "ankara", Count = 30, Geocode = geoSearch });

But tweets.Statuses returns empty. If I remove Geocode part from SearchOptions I can get results. But I want to get tweets in a specific location radius.

I manage to do it with Twitterizer library:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var tokens = new Twitterizer.OAuthTokens
            {
                ConsumerKey = @"",
                ConsumerSecret = @"",
                AccessToken = @"-",
                AccessTokenSecret = @""
            };

            var response = Twitterizer.TwitterSearch.Search(tokens, " ",
              new Twitterizer.SearchOptions
              {
                  Count = 5,
                  GeoCode = "39.920687,32.853970,50km"
              });
            if (response.Result != Twitterizer.RequestResult.Success)
                return;
            var index = 0;
            foreach (var status in response.ResponseObject)
            {
                index++;
                Console.WriteLine(index);
                Console.WriteLine(status.Text);
                Console.WriteLine(status.CreatedDate);


            }

            Console.ReadLine();
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM