Software Architect / Microsoft MVP (AI) and Pluralsight Author

C#, Social Opinion API, Twitter API v2

Extracting Timelines on Twitter with the Tweets Timeline and Social Opinion API

Timelines are an essential feature on Twitter. It’s where most of the action is. The Tweets Timeline API lets you extract published Tweets from a given users timeline via the numerical user id.

I’ve added support for this new Twitter API v2 endpoint to the Social Opinion API. This lets you call the new endpoint with 2 lines of code (just like the User Mention feature I added a few weeks ago).

Key Features

Here are some of the key features of the endpoint:

  • Access to a single accounts most recent Tweets, ReTweets, replies and Quote Tweets
  • Public and Private Metrics (impressions, likes etc)
  • Upto 3,200 Tweets per request
  • Tweets delivered in reverse chronological order (newest to oldest)
  • Ability to specify date range when searching
  • Support for Application scoped requests (Bearer Token) and User scoped requests (OAuth 1.0a)

Let’s look at an example of it in action.

An Example

Here we are calling the Tweet Timeline endpoint:

TimelineService timeLineService = new TimelineService(oAuthInfo);

timeLineService.GetUserTweetsTimeline("958676983", null, true, true, 100, null, null, null, null);

The first parameter -958676983, is the ID of the Twitter account we’re interested in. You can get this using the User Lookup API.

We’re telling the API we want 100 tweets and to exclude retweets (true) and to exclude replies (true).  Other parameters include:

  • pagination_token
  • start_time
  • end_time
  • since_id
  • until_id

The method returns an object UserTweetTimelineModel which contains many properties.  Here we can see the root level object for each Tweet:

public class TweetDatum


        public DateTime created_at { get; set; }

        public OrganicMetrics organic_metrics { get; set; }

        public bool possibly_sensitive { get; set; }

        public TweetNonPublicMetrics non_public_metrics { get; set; }

        public string id { get; set; }

        public string source { get; set; }

        public string conversation_id { get; set; }

        public TweetPublicMetrics public_metrics { get; set; }

        public string text { get; set; }

        public string reply_settings { get; set; }

        public string lang { get; set; }

        public string author_id { get; set; }

        public Entities entities { get; set; }

        public Attachments attachments { get; set; }

        public IList<ContextAnnotation> context_annotations { get; set; }

        public string in_reply_to_user_id { get; set; }

        public IList<ReferencedTweet> referenced_tweets { get; set; }


A closer look at the OrganicMetrics datatype shows we also have  access to important metrics:

public class OrganicMetrics


        public int impression_count { get; set; }

        public int reply_count { get; set; }

        public int user_profile_clicks { get; set; }

        public int retweet_count { get; set; }

        public int like_count { get; set; }

        public int? url_link_clicks { get; set; }


A Closer Look at the Debugger

When we examine the debugger, we can see the following data is returned from our method call:

timeLineService.GetUserTweetsTimeline("958676983", null, true, true, 100, null, null, null, null);

We can expand the data property to access the tweets from the Social Opinion timeline:

We can open one of these to see further insights such as the impressions:

Furth insights can be accessed via Context Annotations:

These are just a few of the properties in the object graph. You can find out what else is available my checking out the Social Opinion AI.

Wrapping Up

There are many use cases for this endpoint and the enhanced signals that it delivers.

You can use this enpoint to:

  • identify brand affinity in a timline
  • identify common topics being mentioned in a timeline
  • create custom workflows or dynamic engagement processes
  • ..and more!

You can find the Social Opinion API on NuGet here.

Got a question? Interested in an integration or feature request? Get in contact with me.

Get the latest content and code from the blog posts!
I respect your privacy. No spam. Ever.

Leave a Reply