5

Support for the new Twitter API Likes Lookup added to Social Opinion API

 3 years ago
source link: https://jamiemaguire.net/index.php/2021/06/12/support-for-the-new-twitter-api-likes-lookup-added-to-social-opinion-api/?utm_campaign=support-for-the-new-twitter-api-likes-lookup-added-to-social-opinion-api
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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

Support for the new Twitter API Likes Lookup added to Social Opinion API

I’ve implemented all Likes Lookup endpoints that were recently shipped by Twitter. These are available in my NuGet package and on GitHub.

You can do the following with this latest update:

  • Get a list of users that like a tweet
  • Get a user’s liked tweets
  • Like a tweet
  • Unlike a tweet

Each method simple to use and you can use them with a few lines of code. The first thing you need to do is create an instance of the new Likes Lookup service and pass in your OAuth tokens:

LikesService likesService = new LikesService(oAuthInfo);

You are now free to call each of the methods.

Users that Like a Tweet

This method will get you a list of users that like a given tweet id.

Each item in the list will contain all publicly available properties for the user on Twitter.

List<User> UsersWhoLikedATweet = likesService.GetLikingUsers("1402547535391121409");

You can see an example of the user data each item will contain here:

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

Users Liked Tweets

This method will give you of the tweets a given user id has liked:

List<LikesModel> listOfTweets = likesService.GetUsersLikedTweets("38906681", 5, 1);

You can see an example of some of the tweet data each item will contain here:

public class Datum
public Entities entities { get; set; }
public string in_reply_to_user_id { get; set; }
public string reply_settings { get; set; }
public string id { get; set; }
public DateTime created_at { get; set; }
public string text { get; set; }
public string conversation_id { get; set; }
public string source { get; set; }
public string lang { get; set; }
public string author_id { get; set; }
public List<ReferencedTweet> referenced_tweets { get; set; }
public bool possibly_sensitive { get; set; }
public PublicMetrics public_metrics { get; set; }
public List<ContextAnnotation> context_annotations { get; set; }

Like a Tweet

This method will let you programmatically like a tweet for a given user id (via OAuth) against a given tweet id:

bool hasLiked = likesService.LikeTweet("958676983", "1402590400557240324");

Unlike a Tweet

This method will let you programmatically unlike a tweet for a given user id (via OAuth) against a given tweet id:

bool unliked = likesService.UnLikeTweet("958676983", "1402590400557240324");

Each return a true/false based on the results of the method call.

Use Cases

There are a few things you can do with these endpoints.

Audience Insights

Use this to better understand your audience and followers. Understand what they “like”, infer Context Annotation or apply further analytics such as NER and sentiment analysis to see what they care about.

Outreach and Audience Building

Identify popular tweets using metrics such as Likes, Impressions etc. Next, list users that have liked your popular tweets.

Profiling

Dive deep into user profiles. Use the Timelines API and the Tweets Lookup to better understand what account tweets about and what they like. Package this into an analytics report. These are just a few ideas, and you probably have your own.

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

More information on the Likes Lookup API here.

If you want to quickly understand your followers, analytics or automate 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.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK