In my last blog post, I introduced the Twitter Labs Sampled Stream integration with the Social Opinion API. In this blog post I introduce the final integration from the Twitter Labs initiative – the Hide Replies API.
What is the Hide Replies API?
With over 166 million Daily Monetizable Active Users (mDAU’s), it’s safe to say Twitter is a popular platform. Tweets can receive hundreds of replies which can be difficult for users to manage.
Bad actors can high-jack threads and post abusive or offensive Tweets and whilst the option to mute threads or block users is one approach, you don’t always want to take the brute force approach.
The Hide Replies API is a new API that lets developers build custom solutions which can programmatically hide replies to Tweets using their own unique requirements.
What kind of Tweets can you hide?
The Hide Replies API lets you hide any Tweets in a conversation that were started by the author that has granted access to your Twitter developer application. You can hide replies and replies of a reply.
Does the Hide Reply API have any constraints?
At the time of writing, the Hide Replies API is in Labs and you can hide up to 10 Tweets every 15 minutes. Multiple users can use your application and any application that implements the Hide Replies API can moderate (or hide) up to 725 Tweets per conversation.
Other constraints include:
- unable to hide Retweets of a reply
- unable to hide replies that have been unhidden by the user
- unable to the authors original Tweet and any of their replies
At the time of writing, you can’t “unhide” a hidden reply. The Dev Rel Team at Twitter have advised they are currently working on adding support for this. Another point worth mentioning is that an increase on the number requests you can make is also on the cards (currently you can only make 10 every 15 minutes)
Why would you want to use the Hide Replies API?
There are a few reasons why you might want to use the Hide Replies API. These can include but aren’t limited to:
- Making it easier for users to manage popular conversations
- Improving the conversational health of discussions
- Making sure conversations stay on topic
You can think of the Hide Replies API as another tool that forms one part of your content moderation toolbox.
How do you Hide Replies using the Social Opinion API?
Like other Labs implementations, the Hide Replies API integration has been encapsulated with a service class that handles authentication, any required, requests and data processing for you.
First, you create an instance of the HideReplyService class and pass in the OAuth credentials. You can see this here:
HideReplyService hideRepliesService = new HideReplyService(oAuthInfo);
Next, you identify the Tweet ID that you want to hide and call the method HideReply passing this in as a parameter:
HideReplyModel model = hideRepliesService.HideReply("1266378790747303939");
When this method has finished object HideReplyModel is returned which contains a Boolean property to indicate the outcome of the operation.
This is all fine and well but let’s look an example of this in action. Here we have an initial Tweet sent by the user account @socialopinions:
A new reply is then added by my personal account:
After we click Reply, the reply has been added:
Clicking on the reply from my personal account, we can see the Tweet ID in the query string – 1266378790747303939 :
We’re going to hide this reply despite my plea! We can do this by taking the Tweet Id that we’ve just identified and using the Social Opinion API HideReplyService class:
HideReplyService hideRepliesService = new HideReplyService(oAuthInfo); HideReplyModel model = hideRepliesService.HideReply("1266378790747303939");
After calling the method HideReply, we can examine the output in the Visual Studio Debugger. Here we can see the following information in the debugger:
You can see there is a property which belongs to the HideReplyModel called hidden which has been set to true. This lets you know the Tweet has been successfully hidden!
Verifying this in Twitter
We can further test this has been successful by viewing the original Tweet, when we do this we get the following message:
This further validates that our selected Tweet was hidden (the Tweet sent from my personal account).
After clicking ok, we can see our thread has now has no comments BUT we can view the reply we’ve just hidden by clicking on the button on the bottom right:
……here we see the previously added Tweet that was hidden:
So that’s a run through of the functionality and how you can programmatically hide replies in a thread on Twitter. It’s straightforward with the Social Opinion API integration.
Use Cases and Further Ideas
Whilst the functionality we’ve just ran through is certainly useful, the real benefits come into play when you augment Hide Replies with technology such as machine learning, text analytics or computer vision.
Supplying the tweet id to the Tweet lookup API will give you access to the tweet copy and other information related to the Tweet such as images in the Tweet and the tweet copy itself.
Use technology like ML.NET and machine learning algorithms it ships with such as binary classification, multiclass classification or k-NN (k-nearest-neighbour) to help you categorise and identify tweets with sensitive content.
Bots and Bad Actors
With custom code, you could identify and keep track of Twitter Bots or “bad actors” on Twitter. When theses account hit a certain “offence threshold”, your custom code could start to hide replies from these accounts. Should you choose this route, Twitter recently posted guidance on their blog to help you determine how to best approach these type of situations, so you can understand what constitutes a good approach.
Keep things on track with Machine Learning and Context Annotations
One of the more recent additions to the Twitter API is the concept of Context Annotations, Entities and Domains. I’ve introduced these in several blog posts, you can find out more here. These are further insights that you now get as part of Tweet payload.
For example, here you can see some examples of Context Annotations and Domains related to a query “iphone”:
You can extract the content annotations from each reply and make sure, it’s relevant to the current thread, if not, you could hide the reply. This doesn’t have to be a binary decision that matches against keywords returning true or false either.
You could dynamically create a small training model that determined the “topic” an incoming reply belongs to. Next, you could calculate a score between 0 and 1 which is then used to determine if the reply should be hidden or not.
In this blog post I’ve introduced the Hide Replies API integration with the Social Opinion API. We’ve seen how you can use this integration to programmatically hide replies in discussions on Twitter. We’ve also considered some of the use cases of this API and explored ideas such as integrating machine learning algorithm to help augment the API capability.
You can download the Social Opinion API for free at NuGet.
You can find out more about the Hide Replies API here.