{"id":2778,"date":"2021-07-17T08:00:11","date_gmt":"2021-07-17T07:00:11","guid":{"rendered":"https:\/\/jamiemaguire.net\/?p=2778"},"modified":"2021-07-18T10:25:50","modified_gmt":"2021-07-18T09:25:50","slug":"support-for-the-new-twitter-api-tweet-blocks-endpoint-added-to-social-opinion-api","status":"publish","type":"post","link":"https:\/\/jamiemaguire.net\/index.php\/2021\/07\/17\/support-for-the-new-twitter-api-tweet-blocks-endpoint-added-to-social-opinion-api\/","title":{"rendered":"Support for the new Twitter API Tweet Blocks Endpoint added to Social Opinion API"},"content":{"rendered":"<p>I\u2019ve implemented the new V2 Blocks endpoint that recently shipped by Twitter. This is available in my NuGet package and on GitHub. It\u2019s written in C#.<\/p>\n<p>This endpoint lets you programmatically:<\/p>\n<ul>\n<li>Get a list of accounts an account has blocked<\/li>\n<li>Block an account<\/li>\n<li>Unblock an account<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>You can use these endpoints to build a better experience on the platform. For example, by creating configurable business rules around why an account should be blocked. Another example might be applying machine learning to discover the type of accounts a person tends to block<\/p>\n<h2>Using The Counts Enpoint with The Social Opinion API<\/h2>\n<p>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 Tweet Service and pass in your OAuth tokens:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">BlocksService tweetsService = new BlocksService(oAuthInfo);<\/pre>\n<p>You are now free to call each of the methods<\/p>\n<h2>Get a List of Accounts an Account Has Blocked<\/h2>\n<p>This method will get you a list of the accounts that the authentication account has blocked.<\/p>\n<p>Each item (BlockModel) in the list will contain all publicly available properties for each blocked user.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">List&lt;BlocksModel&gt; lists = blocksService.GetBlocks(\"958676983\", 10);<\/pre>\n<p>You can see an example of the data you get here:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public class BlockData\r\n{\r\n\u00a0\u00a0\u00a0 public string url { get; set; }\r\n\u00a0\u00a0\u00a0 public string profile_image_url { get; set; }\r\n\u00a0\u00a0\u00a0 public bool verified { get; set; }\r\n\u00a0\u00a0\u00a0 public PublicMetrics public_metrics { get; set; }\r\n\u00a0\u00a0\u00a0 public string name { get; set; }\r\n\u00a0\u00a0\u00a0 public Entities entities { get; set; }\r\n\u00a0\u00a0\u00a0 public string id { get; set; }\r\n\u00a0\u00a0\u00a0 public string description { get; set; }\r\n\u00a0\u00a0\u00a0 public bool @protected { get; set; }\r\n\u00a0\u00a0\u00a0 public string username { get; set; }\r\n\u00a0\u00a0\u00a0 public string location { get; set; }\r\n\u00a0\u00a0\u00a0 public DateTime created_at { get; set; }\r\n\u00a0\u00a0\u00a0 public string pinned_tweet_id { get; set; }\r\n}<\/pre>\n<p>We can take a closer look at the Public Metrics and see some other properties:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public class PublicMetrics\r\n{\r\n\u00a0\u00a0\u00a0 public int followers_count { get; set; }\r\n\u00a0\u00a0\u00a0 public int following_count { get; set; }\r\n\u00a0\u00a0\u00a0 public int tweet_count { get; set; }\r\n\u00a0\u00a0\u00a0 public int listed_count { get; set; }\r\n\u00a0\u00a0\u00a0 public int retweet_count { get; set; }\r\n\u00a0\u00a0\u00a0 public int reply_count { get; set; }\r\n\u00a0\u00a0\u00a0 public int like_count { get; set; }\r\n\u00a0\u00a0\u00a0 public int quote_count { get; set; }\r\n}<\/pre>\n<p>Further insights about the blocked account are also found in the Entities property for the blocked user such as the bio field, any urls or hashtags they have on their account:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public class Entities\r\n{\r\n\u00a0\u00a0\u00a0 public Description description { get; set; }\r\n\u00a0\u00a0\u00a0 public Url url { get; set; }\r\n\u00a0\u00a0\u00a0 public List&lt;Annotation&gt; annotations { get; set; }\r\n\u00a0\u00a0\u00a0 public List&lt;Url&gt; urls { get; set; }\r\n\u00a0\u00a0\u00a0 public List&lt;Hashtag&gt; hashtags { get; set; }\r\n\u00a0\u00a0\u00a0 public List&lt;Mention&gt; mentions { get; set; }\r\n}<\/pre>\n<h2>Block an Account<\/h2>\n<p>This method lets the authenticated account block a target user account<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">bool blockedResult = blocksService.Block(\"958676983\", \"34655603\");<\/pre>\n<p>The first parameter is the id you are blocking on behalf of.\u00a0 The second parameter is the target id of the account you want to block.<\/p>\n<p>A boolean (<strong>true<\/strong>) is returned when the operation has been successful and the account has been blocked.<\/p>\n<h2>Unblock an Account<\/h2>\n<p>This method lets the authenticated account unblock a target user account<\/p>\n<p>The first parameter is the id you are unblocking on behalf of.\u00a0 The second parameter is the target id of the account you want to unblock.<\/p>\n<p>A boolean (<strong>false<\/strong>) is returned when the operation has been successful, and the account has been unblocked<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">bool result = blocksService.UnBlock(\"958676983\", \"34655603\");<\/pre>\n<h2>Use Cases<\/h2>\n<p>There are a few use cases for this, I see the main ones being around creating automation to improve customer or user experience on the platform.<\/p>\n<p><strong>Automation<\/strong><\/p>\n<p>You could apply Azure Cognitive Services Text Analytics and infer the sentiment or detect profanity from an account. You might then decide to automatically block an account after a certain threshold had been reached.<\/p>\n<p><strong>Account Analysis<\/strong><\/p>\n<p>Use the Blocks API in conjunction with the with the Timeline API to create an overview of an account. Based on configurable rules you could block or unblock accounts.<\/p>\n<p><strong>Research<\/strong><\/p>\n<p>Identify accounts that a user tends to block. Use the Recent Search API to fetch data from blocked accounts and identify patterns.<\/p>\n<p style=\"text-align: center;\">~<\/p>\n<p>Free NuGet Package: You can find the free Social Opinion NuGet package <a href=\"https:\/\/www.nuget.org\/packages\/SocialOpinionAPI\/\">here<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<p>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 <a href=\"https:\/\/socialopinion.co.uk\/\">Social Opinion<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve implemented the new V2 Blocks endpoint that recently shipped by Twitter. This is available in my NuGet package and on GitHub. It\u2019s written in C#. This endpoint lets you programmatically: Get a list of&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2779,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[6,83,71,70],"tags":[],"class_list":["post-2778","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c","category-social-opinion","category-social-opinion-api","category-twitter-api-v2"],"_links":{"self":[{"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/posts\/2778","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/comments?post=2778"}],"version-history":[{"count":0,"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/posts\/2778\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/media\/2779"}],"wp:attachment":[{"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/media?parent=2778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/categories?post=2778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/tags?post=2778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}