Software Architect / Microsoft MVP (AI) and Pluralsight Author

C#, Productivity, Social Opinion API, Twitter API v2

Support for Twitter API v2 Retweets endpoint added to Social Opinion API

I’ve implemented the new V2 Retweet endpoint that recently shipped by Twitter.

It’s available in my NuGet package and on GitHub. It’s written in C#.

This endpoint lets you programmatically:

  • Retweet a tweet
  • Remove a retweet
  • Get a list of accounts who retweeted a tweet

 

You can use these new methods in the Social Opinion API to create automation, amplify content or better understand an account by fetching the types of tweets a person tends to retweet.

Using The Retweet Enpoint with The Social Opinion API

You can use this end point with a few lines of code.

The first thing you need to do is create an instance of the Retweet Service and pass in your OAuth tokens:

RetweetsService retweetService = new RetweetsService(oAuthInfo);

You are now free to call each of the methods

Retweeting a tweet.

This method does what it says on the tin. You can use it in a single line of code:

bool retweeted = retweetService.Retweet("958676983", "1413595913331826694");

The first parameter is the user id you are performing the retweet on behalf of.  The second parameter is the target id of the tweet you target.

A Boolean (true) is then returned to let you know if the retweet was successful.

Remove a retweet

Removing a retweet is simple, you can see this here:

bool retweeted = retweetService.RemoveRetweet("958676983", "1413595913331826694");

The first parameter is the user id you are removing the retweet on behalf of.  The second parameter is the target id of the tweet you target.

A boolean (true) is returned when the operation has been successful and the account has been blocked.

GetWhoRetweetedTweet

This method gets you a list of accounts who have retweeted a tweet.  You simply pass in the tweet id and UserModel is returned. This contains all relevant properties for each user that has retweeted a tweet.

You can see an example of some of the data you get here:

public class Data
{
     public DateTime created_at { get; set; }
     public string description { get; set; }
     public Entities entities { get; set; }
     public string id { get; set; }
     public string location { get; set; }
     public string name { get; set; }
     public string pinned_tweet_id { get; set; }
     public string profile_image_url { get; set; }
     public bool is_protected { get; set; }
     public PublicMetrics public_metrics { get; set; }
     public string url { get; set; }
     public string username { get; set; }
     public bool verified { get; set; }
}

 

You might want to take this further and user the id property + the Timeline API to get further insights by fetching a user’s timeline.

Use Cases

There are a few use cases for this API.

Amplify Content and Reach

The Auto Retweet feature in my Twitter Analytics and productivity SaaS Social Opinion lets you configure a setting for your scheduled tweets to automatically retweeted after X number of hours.

This helps you automatically reuse existing tweets and is a good way to get your content in front of a different timezone.

Audience Analytics

Use the API to infer audience insights by building intelligence around what types of tweets accounts tend to retweet.

Automation

Use remove retweet to build automation that cleanses accounts or automatically retweets content based on your own specific business requirements.  Blend in text analytics and machine learning to apply further optmisations.

~

Free NuGet Package: You can find the free Social Opinion NuGet package here.

If you want to understand your followers, get richer analytics, perform social media monitoring, schedule tweets, or automate other aspects of your Twitter account, you can do that using Social Opinion

JOIN MY EXCLUSIVE EMAIL LIST
Get the latest content and code from the blog posts!
I respect your privacy. No spam. Ever.

Leave a Reply