I’ve implemented the new V2 Tweet Count endpoint that recently shipped by Twitter. This is available in my NuGet package and on GitHub.
This endpoint lets you fetch a count of tweets for a given query from the last 7 days.
The coolest part is that you can supply a date range with an associated granularity and the endpoint will give you collection of timeseries information. This can be spliced by day, hour, or minute.
Using The Counts Enpoint
You can use this end point with a few lines of code with the Social Opinion API. The first thing you need to do is create an instance of the Tweet Service and pass in your OAuth tokens:
TweetService tweetsService = new TweetService(oAuthInfo);
Next, call the method:
tweetsService.GetTweetCounts("BTC", DateTime.Now, TweetService.CountsGranularity.Hour, "", DateTime.Now.AddDays(-1), "");
This returns TweetCountsModel. You can see this here:
public class TweetCountData { public DateTime end { get; set; } public DateTime start { get; set; } public int tweet_count { get; set; } } public class Meta { public int total_tweet_count { get; set; } } public class TweetCountsModel { public IList<TweetCountData> data { get; set; } public Meta meta { get; set; } }
You can see an example payload here:
In the above the query is set to BTC. The granularity is set to Hour and the start and end date for the query is the 25/06/2021. You can see the tweet count for one splice of the time range is 5,177.
Being able to quickly gauge the size of conversation can be useful. You can use this as a temp check to see how popular a particular topic is. You can then use the Recent Search API to dig deeper and surface extra insights on the topic. Approaching things this way means you can save money in terms of data spend.
~
Free NuGet Package: You can find the free NuGet package here.
If you want to quickly understand your followers, get richer analytics or automate aspects of your Twitter account, you can do that using Social Opinion.
Leave a Reply