{"id":208662,"date":"2014-01-10T17:25:02","date_gmt":"2014-01-10T13:25:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=208662"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=208662","title":{"rendered":"<span class=\"post_title\">Twitter \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0442\u0432\u0438\u0442\u043e\u0432 \u0438 \u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<i>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u043a\u0443\u0431\u0438\u043a\u0438 \u0441\u043b\u043e\u0436\u0438\u043b\u0438\u0441\u044c&#8230;<\/i><\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/8ff\/bb3\/781\/8ffbb3781039d34da71f79e75a5c1004.jpg\" alt=\"image\"\/><\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0432\u043e\u043b\u0435\u044e \u0441\u0443\u0434\u0435\u0431 \u0432\u044b\u043f\u0430\u043b\u043e \u043f\u0438\u0441\u0430\u0442\u044c twitter \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043d\u043e \u0432\u044b \u0435\u0449\u0435 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435 \u0441 \u0447\u0435\u0433\u043e \u043d\u0430\u0447\u0430\u0442\u044c, \u0442\u043e \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u0432\u044b\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u0432 \u0438\u0442\u043e\u0433\u0435, \u043f\u0440\u0438\u0432\u0435\u0434\u0443\u0442 \u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e, \u0443\u043c\u0435\u044e\u0449\u0435\u043c\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u0432\u0438\u0442\u044b \u043d\u0430 \u043b\u0435\u043d\u0442\u0443 \u0438 \u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c.<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e \u043f\u0443\u043d\u043a\u0442\u0430\u043c:<\/p>\n<p>  1. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u0435\u043d \u0430\u043a\u043a\u0430\u0443\u043d\u0442 \u043d\u0430 <a href=\"https:\/\/twitter.com\/\">Twitter<\/a>. \u0415\u0449\u0435 \u043d\u0435\u0442? \u0422\u043e\u0433\u0434\u0430, \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f.<br \/>   \u0417\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u0438\u043b\u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432\u0430\u0448 <b>\u043b\u043e\u0433\u0438\u043d<\/b> \u0438 <b>\u043f\u0430\u0440\u043e\u043b\u044c<\/b> \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u043f\u0443\u043d\u043a\u0442\u0443.<\/p>\n<p>  2. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043d\u0430 \u0441\u0430\u0439\u0442 <a href=\"https:\/\/dev.twitter.com\/\">Twitter Developers<\/a>, \u0433\u0434\u0435, \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f <br \/>   \u0442\u0440\u0438\u0442\u0442\u0435\u0440 <b>\u043b\u043e\u0433\u0438\u043d\u043e\u043c<\/b> \u0438 <b>\u043f\u0430\u0440\u043e\u043b\u0435\u043c<\/b>. \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0448\u043b\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e, \u043d\u0443\u0436\u043d\u043e \u0432 \u043c\u0435\u043d\u044e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u0432\u044b\u0431\u0440\u0430\u0442\u044c <br \/>   \u043f\u0443\u043d\u043a\u0442 \u00abMy applications\u00bb \u0438 \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0432\u0448\u0435\u0439\u0441\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043d\u0430\u0436\u0430\u0442\u044c \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/06d\/72a\/faf\/06d72afaf78fa7b6c862c50b9755f27f.jpg\" alt=\"image\"\/><\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/080\/cd4\/b90\/080cd4b90ff1d0ade0541e9d8812a8eb.jpg\" alt=\"image\"\/><\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u0442\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0435\u043c\u0443(\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e) \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0442\u0441\u044f 2 \u043a\u043b\u044e\u0447\u0430:<br \/>   <b>Consumer key<\/b> \u0438 <br \/>   <b>Consumer secret<\/b><br \/>   \u041e\u043d\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 OAuth settings \u0432\u043a\u043b\u0430\u0434\u043a\u0438 Details \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/content.foto.mail.ru\/mail\/a_golovinskaya\/_myphoto\/h-12.jpg\" alt=\"image\"\/><\/p>\n<p>  3. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f twitter \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 OAuth. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u044d\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"http:\/\/habrahabr.ru\/post\/103365\/\">\u0422\u0432\u0438\u0442\u0442\u0435\u0440 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c\u0438 \u0440\u0443\u043a\u0430\u043c\u0438 \u043d\u0430 C#. \u0427\u0430\u0441\u0442\u044c 1: \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f OAuth<\/a>. \u0412\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <br \/>  \u0438\u0437 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438. \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u0443\u0434\u0430\u0447\u043d\u043e, \u0442\u043e \u0432 \u0438\u0442\u043e\u0433\u0435 \u0432\u044b \u043f\u0440\u043e\u0439\u0434\u0435\u0442\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e OAuth \u0438 \u0432\u0430\u043c \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0442\u0441\u044f \u0435\u0449\u0435 2 \u0432\u0430\u0436\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<br \/>  <b>Access token<\/b> \u0438 <br \/>  <b>Access token secret<\/b><br \/>  \u041e\u043d\u0438 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 Your access token \u0432\u043a\u043b\u0430\u0434\u043a\u0438 Details \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0422\u0430\u043a\u0436\u0435, \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u043e\u043b\u0435 <b>Access level<\/b> \u0432 \u044d\u0442\u043e\u043c \u0436\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0433\u043b\u043e \u043f\u043e\u0441\u0442\u0438\u0442\u044c \u0442\u0432\u0438\u0442\u044b \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043e\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u0432 <i>Read, write, and direct messages<\/i>. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c Access \u043d\u0430 \u0432\u043a\u043b\u0430\u0434\u043a\u0435 Settings \u0438 \u0432\u043d\u043e\u0432\u044c \u043f\u0440\u043e\u0439\u0442\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e OAuth.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/85f\/9db\/016\/85f9db0161c580e37b22aece4c5778e7.jpg\" alt=\"image\"\/><\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u043e\u0442\u043a\u0440\u043e\u0435\u0442\u0435 \u0432\u0430\u0448 \u0430\u043a\u043a\u0430\u0443\u043d\u0442 \u0442\u0432\u0438\u0442\u0442\u0435\u0440, \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u0442\u0435 \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438 \u043e\u0442\u043a\u0440\u043e\u0435\u0442\u0435 \u043c\u0435\u043d\u044e \u00ab\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u00bb, \u0442\u043e \u0442\u0430\u043c \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043d\u0430 <a href=\"https:\/\/dev.twitter.com\/\">Twitter Developers<\/a>:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/faa\/13e\/a88\/faa13ea883b5510efa835f1ba9199e67.jpg\" alt=\"image\"\/><\/p>\n<p>  4. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u043a\u043b\u044e\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0445 \u044d\u0442\u0430\u043f\u0430\u0445:<br \/>  <b>Consumer key<\/b><br \/>  <b>Consumer secret<\/b><br \/>  <b>Access token<\/b><br \/>  <b>Access token secret<\/b><\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 MessageSender, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439:<\/p>\n<pre><code class=\"cs\">using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Security.Cryptography; using System.Net; using System.IO;  namespace TwitterOAuth {     class MessageSender     {         private readonly string consumerKey;         private readonly string consumerSecret;         private readonly string oauthToken;         private readonly string oauthTokenSecret;          private const string headerFormat = &quot;OAuth oauth_nonce=\\&quot;{0}\\&quot;, oauth_signature_method=\\&quot;{1}\\&quot;, &quot; +               &quot;oauth_timestamp=\\&quot;{2}\\&quot;, oauth_consumer_key=\\&quot;{3}\\&quot;, &quot; +               &quot;oauth_token=\\&quot;{4}\\&quot;, oauth_signature=\\&quot;{5}\\&quot;, &quot; +               &quot;oauth_version=\\&quot;{6}\\&quot;&quot;;          \/\/\/ &lt;summary&gt;         \/\/\/ \u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0435 \u043a\u043b\u044e\u0447\u0438         \/\/\/ &lt;\/summary&gt;         public MessageSender(string consumer_key, string consumer_secret, string oauth_token, string oauth_token_secret)         {             this.consumerKey = consumer_key;             this.consumerSecret = consumer_secret;             this.oauthToken = oauth_token;             this.oauthTokenSecret = oauth_token_secret;         }          \/\/\/ &lt;summary&gt;         \/\/\/ \u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043b\u0438\u0447\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e         \/\/\/ &lt;\/summary&gt;         \/\/\/ &lt;param name=&quot;user&quot;&gt;without @&lt;\/param&gt;         \/\/\/ &lt;param name=&quot;text&quot;&gt;&lt;\/param&gt;         public void SendDirectMessage(string user, string text)         {             string post_data;             string resource_url;              string authHeader = GetPostDirectMessageBaseString(text, user, oauthToken, oauthTokenSecret, out post_data, out resource_url);             Send(resource_url, post_data, authHeader);         }          \/\/\/ &lt;summary&gt;         \/\/\/ \u041f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u043d\u0430 \u043b\u0435\u043d\u0442\u0443         \/\/\/ &lt;\/summary&gt;         \/\/\/ &lt;param name=&quot;text&quot;&gt;&lt;\/param&gt;         public void SendTwit(string text)         {             string post_data;             string resource_url;              string authHeader = GetStatusBaseString(text, oauthToken, oauthTokenSecret, out post_data, out resource_url);             Send(resource_url, post_data, authHeader);         }          private void Send(string resource_url, string post_data, string auth_header)         {             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(resource_url);             request.Headers.Add(&quot;Authorization&quot;, auth_header);             request.Method = &quot;POST&quot;;             request.ContentType = &quot;application\/x-www-form-urlencoded&quot;;             request.ContentLength = post_data.Length;              using (Stream stream = request.GetRequestStream())             {                 byte[] content = ASCIIEncoding.ASCII.GetBytes(post_data);                 stream.Write(content, 0, content.Length);             }             try             {                 WebResponse response = request.GetResponse();                 Console.WriteLine(response.ToString());             }             catch (WebException e)             {                 Console.WriteLine(e.Status.ToString());             }         }          private string GetBaseString(string oauth_token, string oauth_token_secret, string post_data, string resource_url)         {             var oauth_version = &quot;1.0&quot;;             var oauth_signature_method = &quot;HMAC-SHA1&quot;;             var oauth_nonce = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));             var timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);             var oauth_timestamp = Convert.ToInt64(timeSpan.TotalSeconds).ToString();              var baseFormat = &quot;oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}&quot; +                 &quot;&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&&quot; + post_data;              var baseString = string.Format(baseFormat,                                         consumerKey,                                         oauth_nonce,                                         oauth_signature_method,                                         oauth_timestamp,                                         oauth_token,                                         oauth_version                                         );              baseString = string.Concat(&quot;POST&&quot;, Uri.EscapeDataString(resource_url),                          &quot;&&quot;, Uri.EscapeDataString(baseString));              \/\/Encrypt data             var compositeKey = string.Concat(Uri.EscapeDataString(consumerSecret),                         &quot;&&quot;, Uri.EscapeDataString(oauth_token_secret));              string oauth_signature;             using (HMACSHA1 hasher = new HMACSHA1(ASCIIEncoding.ASCII.GetBytes(compositeKey)))             {                 oauth_signature = Convert.ToBase64String(                     hasher.ComputeHash(ASCIIEncoding.ASCII.GetBytes(baseString)));             }              \/\/Finish Auth header             var authHeader = string.Format(headerFormat,                                     Uri.EscapeDataString(oauth_nonce),                                     Uri.EscapeDataString(oauth_signature_method),                                     Uri.EscapeDataString(oauth_timestamp),                                     Uri.EscapeDataString(consumerKey),                                     Uri.EscapeDataString(oauth_token),                                     Uri.EscapeDataString(oauth_signature),                                     Uri.EscapeDataString(oauth_version)                             );              return authHeader;         }          private string GetStatusBaseString(string status, string oauth_token, string oauth_token_secret, out string post_data, out string resource_url)         {             post_data = &quot;status=&quot; + Uri.EscapeDataString(status);             resource_url = &quot;https:\/\/api.twitter.com\/1.1\/statuses\/update.json&quot;;              return GetBaseString(oauth_token, oauth_token_secret, post_data, resource_url);         }          private string GetPostDirectMessageBaseString(string text, string screen_name, string oauth_token, string oauth_token_secret, out string post_data, out string resource_url)         {             post_data = &quot;screen_name=&quot; + Uri.EscapeDataString(screen_name) + &quot;&text=&quot; + Uri.EscapeDataString(text);             resource_url = &quot;https:\/\/api.twitter.com\/1.1\/direct_messages\/new.json&quot;;              return GetBaseString(oauth_token, oauth_token_secret, post_data, resource_url);         }     } } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043d\u0430 \u043b\u0435\u043d\u0442\u0443, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043ce\u0442\u043e\u0434 SendTwit(\u00absome message\u00bb),<br \/>  \u0430 \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043b\u0438\u0447\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 SendDirectMessage(\u00abuser\u00bb, \u00absome message\u00bb)<\/p>\n<pre><code class=\"cs\">        static void Main(string[] args)         {             \/\/\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f             MessageSender ms = new MessageSender(consumerKey,                 consumerSecret,                 oauth_token,                 oauth_token_secret);             ms.SendTwit(&quot;I can send twit&quot;);             \/\/\u0437\u0434\u0435\u0441\u044c \u043d\u0443\u0436\u043d\u043e \u0432\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438\u043c\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f             ms.SendDirectMessage(&quot;user&quot;, &quot;Direct message for user&quot;);              Console.ReadLine();         } <\/code><\/pre>\n<p>  <b>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/b> \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043b\u0435\u043d\u0442\u0443 \u0438 \u043f\u0438\u0448\u0438\u0442\u0435 \u0442\u0435\u043a\u0441\u0442 \u043b\u0430\u0442\u0438\u043d\u0438\u0446\u0435\u0439.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0442\u043e \u0432\u043e\u0442 \u0432\u0430\u043c <a href=\"https:\/\/dev.twitter.com\/docs\/api\/1.1\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f REST API v1.1 Resources<\/a>. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 <a href=\"https:\/\/dev.twitter.com\/docs\/api\/1.1\/post\/direct_messages\/new\">\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/a>, \u0432 \u043a\u043e\u0434\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430: screen_name \u0438 text, \u0430 resource_url \u0431\u0435\u0440\u0435\u0442\u0441\u044f \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438: \u0440\u0430\u0437\u0434\u0435\u043b Example Request, \u043f\u043e\u043b\u0435 POST<\/p>\n<pre><code class=\"cs\"> private string GetPostDirectMessageBaseString(string text, string screen_name, string oauth_token, string oauth_token_secret, out string post_data, out string resource_url)         {             post_data = &quot;screen_name=&quot; + Uri.EscapeDataString(screen_name) + &quot;&text=&quot; + Uri.EscapeDataString(text);             resource_url = &quot;https:\/\/api.twitter.com\/1.1\/direct_messages\/new.json&quot;;              return GetBaseString(oauth_token, oauth_token_secret, post_data, resource_url);         } <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u0435\u0436\u0434\u0443 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0441\u0442\u0430\u0432\u0438\u0442\u0441\u044f <b>&#038;<\/b>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u0430\u0436\u0435\u043d \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f Signature Base String \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 GetBaseString. \u0427\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f OAuth tool. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u0442\u043a\u0440\u043e\u0439\u0442\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/dev.twitter.com\/docs\/api\/1.1\/post\/direct_messages\/new\">\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/a>, \u043d\u0430\u0439\u0434\u0438\u0442\u0435 \u0441\u043f\u0440\u0430\u0432\u0430 OAuth tool, \u0432 \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0435 \u0432\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u043d\u0430\u0436\u043c\u0438\u0442\u0435 Generate Oauth signature<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/89e\/e57\/7f2\/89ee577f2268a6507763e992c0efea88.jpg\" alt=\"image\"\/><\/p>\n<p>  \u0412\u043d\u0438\u0437\u0443 \u043e\u0442\u043a\u0440\u044b\u0432\u0448\u0435\u0439\u0441\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u043f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, URI, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0430\u0436\u043c\u0435\u0442\u0435 \u043a\u043d\u043e\u043f\u043a\u0443 <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/e43\/76e\/36b\/e4376e36b6a318002dd72b6f568228f0.jpg\" alt=\"image\"\/> \u0442\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f Signature base string, Authorization header \u0438 \u0442.\u0434.<\/p>\n<p>  \u0423\u0434\u0430\u0447\u0438!    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/208662\/\"> http:\/\/habrahabr.ru\/post\/208662\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<i>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u043a\u0443\u0431\u0438\u043a\u0438 \u0441\u043b\u043e\u0436\u0438\u043b\u0438\u0441\u044c&#8230;<\/i><\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/8ff\/bb3\/781\/8ffbb3781039d34da71f79e75a5c1004.jpg\" alt=\"image\"\/><\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0432\u043e\u043b\u0435\u044e \u0441\u0443\u0434\u0435\u0431 \u0432\u044b\u043f\u0430\u043b\u043e \u043f\u0438\u0441\u0430\u0442\u044c twitter \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043d\u043e \u0432\u044b \u0435\u0449\u0435 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435 \u0441 \u0447\u0435\u0433\u043e \u043d\u0430\u0447\u0430\u0442\u044c, \u0442\u043e \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u0432\u044b\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u0432 \u0438\u0442\u043e\u0433\u0435, \u043f\u0440\u0438\u0432\u0435\u0434\u0443\u0442 \u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e, \u0443\u043c\u0435\u044e\u0449\u0435\u043c\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u0432\u0438\u0442\u044b \u043d\u0430 \u043b\u0435\u043d\u0442\u0443 \u0438 \u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-208662","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/208662","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=208662"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/208662\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=208662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=208662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=208662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}