{"id":280503,"date":"2016-11-06T12:20:03","date_gmt":"2016-11-06T09:20:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=280503"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=280503","title":{"rendered":"\u0414\u043b\u044f \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432. \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 API \u0412\u041a\u043e\u043d\u0442\u0430\u043a\u0442\u0435 \u043d\u0430 C#"},"content":{"rendered":"<p>\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0442\u0435\u0431\u044f, \u0434\u043e\u0440\u043e\u0433\u043e\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c! \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u043c \u0434\u043b\u044f \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432, \u0432 \u043d\u0435\u0439 \u043e\u043f\u0438\u0441\u0430\u043d \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0433\u043e WindowsForms \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 API \u0441\u043e\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u00ab\u0412\u041a\u043e\u043d\u0442\u0430\u043a\u0442\u0435\u00bb. \u041d\u043e \u044d\u0442\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 (VK.Net \u0438 \u043f\u0440\u043e\u0447\u0438\u0435) \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a API VK.<\/p>\n<p>  <b>\u0417\u0430\u0434\u0430\u0447\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:<\/b><\/p>\n<ol>\n<li>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c User Token \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0432\u0441\u0435 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0433\u043e.<\/li>\n<li>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430 \u0432\u0445\u043e\u0434 ID \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/li>\n<li>\u0412\u044b\u0432\u0435\u0441\u0442\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 \u0441 \u0432\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u043c ID.<\/li>\n<\/ol>\n<p><a name=\"habracut\"><\/a><br \/>  \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438:<\/p>\n<ul>\n<li><a href=\"https:\/\/habrahabr.ru\/post\/146475\/\">xNet<\/a> \u2014 \u0434\u043b\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f GET-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/li>\n<li><a href=\"http:\/\/www.newtonsoft.com\/json\">JSON.Net<\/a> \u2014 \u0434\u043b\u044f \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043d\u0430 \u044d\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/li>\n<\/ul>\n<p>  <a name=\"AppID\"><\/a>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u2014 \u044d\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c ID \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0439\u0442\u0438 \u043d\u0430 <a href=\"https:\/\/vk.com\/apps?act=manage\">VkDevelopers<\/a>, \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u043e\u0435 Standalone \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0437\u0430\u0439\u0442\u0438 \u0432 \u0435\u0433\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438 \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c ApplicationID. <\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0437\u0430\u0445\u043e\u0434\u0438\u043c \u0432 VisualStudio \u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043d\u043e\u0432\u043e\u0435 WindowsForms \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/b><\/p>\n<div class=\"spoiler_text\">\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 JSON.Net \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430 \u043f\u0430\u043a\u0435\u0442\u043e\u0432, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0443: <\/p>\n<blockquote><p>Install-Package Newtonsoft.Json<\/p><\/blockquote>\n<p>  \u0414\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 xNet \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u0439\u0442\u0438 <a href=\"https:\/\/github.com\/X-rus\/xNet\/releases\">\u0441\u044e\u0434\u0430<\/a>, \u0441\u043a\u0430\u0447\u0430\u0442\u044c xNet.dll \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430 \u0441\u0441\u044b\u043b\u043e\u043a.<\/div>\n<\/div>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0434\u0432\u0435 \u0444\u043e\u0440\u043c\u044b: MainForm (\u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e Form1) \u0438 AuthorizationForm. \u0424\u043e\u0440\u043c\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0442\u0430\u043a:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">MainForm<\/b><\/p>\n<div class=\"spoiler_text\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/c0f\/18a\/2c8\/c0f18a2c88bf4b74a0647ea5f9bf1340.png\"\/>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">AuthorizationForm<\/b><\/p>\n<div class=\"spoiler_text\">\u042d\u0442\u0430 \u0444\u043e\u0440\u043c\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 WebBrowser \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c Name = GetToken.  <\/div>\n<\/div>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0444\u0430\u0439\u043b \u043a\u043b\u0430\u0441\u0441\u0430. \u041d\u0430\u0437\u043e\u0432\u0451\u043c \u0435\u0433\u043e VkAPI. <\/p>\n<h4>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u0434\u0430.<\/h4>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 MainForm \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 Button_GetToken:<\/p>\n<pre><code class=\"cs\">private void Button_GetToken_Click(object sender, EventArgs e)         {             AuthorizationForm GetToken = new AuthorizationForm();             GetToken.ShowDialog();         } <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c AuthorizationForm:<\/p>\n<pre><code class=\"cs\">using System; using System.Windows.Forms; using System.IO;  namespace VkAPITutorial {     public partial class AuthorizationForm : Form     {         public AuthorizationForm()         {             InitializeComponent();         }          private void AuthorizationForm_Load(object sender, EventArgs e)         {             GetToken.DocumentCompleted += GetToken_DocumentCompleted;             GetToken.Navigate(&quot;https:\/\/oauth.vk.com\/authorize?client_id=5709976&display=page&redirect_uri=https:\/\/oauth.vk.com\/blank.html&scope=friends&response_type=token&v=5.52&quot;);         }          private void GetToken_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)         {             if (GetToken.Url.ToString().IndexOf(&quot;access_token=&quot;) != 0)             {                 GetUserToken();             }         }          private void GetUserToken()         {             char[] Symbols = { '=', '&' };             string[] URL = GetToken.Url.ToString().Split(Symbols);             File.WriteAllText(&quot;UserInf.txt&quot;, URL[1] + &quot;\\n&quot;);             File.AppendAllText(&quot;UserInf.txt&quot;, URL[5]);             this.Visible = false;         }     } } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0432\u0441\u0451 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443:<\/p>\n<p>  \u041f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f AuthorizationForm \u0441 Web-\u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u043c, \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430:<\/p>\n<blockquote>\n<pre>https:\/\/oauth.vk.com\/authorize?client_id=ApplicationID&display=page&redirect_uri=https:\/\/oauth.vk.com\/blank.html&scope=friends&response_type=token&v=5.52<\/pre>\n<\/blockquote>\n<p>  \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <b>client_id<\/b> \u2014 \u044d\u0442\u043e ID \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u0432 <a href=\"#AppID\">\u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438<\/a>. \u041f\u043e\u0441\u043b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 <b>scope<\/b> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u044b \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c, \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/vk.com\/dev\/permissions\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  \u041f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u043b\u0438 \u0432 \u0430\u0434\u0440\u0435\u0441\u0435 <b>access_token<\/b>, \u0435\u0441\u043b\u0438 \u0434\u0430, \u0442\u043e \u043c\u044b \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u0430\u0434\u0440\u0435\u0441 \u0438 \u0437\u0430\u043d\u043e\u0441\u0438\u043c \u0432 \u0444\u0430\u0439\u043b token \u0438 ID \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u043b\u0441\u044f. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e AuthorizationForm \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f. \u0422\u043e\u043a\u0435\u043d \u043f\u043e\u043b\u0443\u0447\u0435\u043d!<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u0438 \u0432\u044b\u0432\u043e\u0434\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043c\u044f, \u0444\u0430\u043c\u0438\u043b\u0438\u044e, \u0433\u043e\u0440\u043e\u0434, \u0441\u0442\u0440\u0430\u043d\u0443 \u0438 \u0444\u043e\u0442\u043e. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438, \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043d\u043e \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0445 \u0432 \u043e\u0434\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435.<\/p>\n<p>  \u041e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0439\u043b VkAPI.cs:<\/p>\n<pre><code class=\"cs\">using System.Collections.Generic; using xNet; using Newtonsoft.Json;  namespace VkAPITutorial {     class VkAPI     {         private const string __APPID = &quot;ApplicationId&quot;;  \/\/ID \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f         private const string __VKAPIURL = &quot;https:\/\/api.vk.com\/method\/&quot;;  \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432         private string _Token;  \/\/\u0422\u043e\u043a\u0435\u043d, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439\u0441\u044f \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445          public VkAPI(string AccessToken)         {             _Token = AccessToken;         }          public Dictionary&lt;string, string&gt; GetInformation(string UserId, string[] Fields)  \/\/\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c ID          {             HttpRequest GetInformation = new HttpRequest();             GetInformation.AddUrlParam(&quot;user_ids&quot;, UserId);             GetInformation.AddUrlParam(&quot;access_token&quot;, _Token);             string Params = &quot;&quot;;             foreach (string i in Fields)             {                 Params += i + &quot;,&quot;;             }             Params = Params.Remove(Params.Length - 1);             GetInformation.AddUrlParam(&quot;fields&quot;, Params);             string Result = GetInformation.Get(__VKAPIURL + &quot;users.get&quot;).ToString();             Result = Result.Substring(13, Result.Length - 15);             Dictionary&lt;string, string&gt; Dict = JsonConvert.DeserializeObject&lt;Dictionary&lt;string, string&gt;&gt;(Result);             return Dict;         }          public string GetCityById(string CityId)  \/\/\u041f\u0435\u0440\u0435\u0432\u043e\u0434 ID \u0433\u043e\u0440\u043e\u0434\u0430 \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435         {             HttpRequest GetCityById = new HttpRequest();             GetCityById.AddUrlParam(&quot;city_ids&quot;, CityId);             GetCityById.AddUrlParam(&quot;access_token&quot;, _Token);             string Result = GetCityById.Get(__VKAPIURL + &quot;database.getCitiesById&quot;).ToString();             Result = Result.Substring(13, Result.Length - 15);             Dictionary&lt;string, string&gt; Dict = JsonConvert.DeserializeObject&lt;Dictionary&lt;string, string&gt;&gt;(Result);             return Dict[&quot;name&quot;];         }          public string GetCountryById(string CountryId)  \/\/\u041f\u0435\u0440\u0435\u0432\u043e\u0434 ID \u0441\u0442\u0440\u0430\u043d\u044b \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435         {             HttpRequest GetCountryById = new HttpRequest();             GetCountryById.AddUrlParam(&quot;country_ids&quot;, CountryId);             GetCountryById.AddUrlParam(&quot;access_token&quot;, _Token);             string Result = GetCountryById.Get(__VKAPIURL + &quot;database.getCountriesById&quot;).ToString();             Result = Result.Substring(13, Result.Length - 15);             Dictionary&lt;string, string&gt; Dict = JsonConvert.DeserializeObject&lt;Dictionary&lt;string, string&gt;&gt;(Result);             return Dict[&quot;name&quot;];         }     } } <\/code><\/pre>\n<p>  \u0418 MainForm:<\/p>\n<pre><code class=\"cs\">using System; using System.Windows.Forms; using System.Collections.Generic; using System.IO;  namespace VkAPITutorial {     public partial class MainForm : Form     {         VkAPI _ApiRequest;         private string _Token;  \/\/\u0422\u043e\u043a\u0435\u043d, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439\u0441\u044f \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445         private string _UserId;  \/\/ID \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f         private Dictionary&lt;string, string&gt; _Response;  \/\/\u041e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u044b          public MainForm()         {             InitializeComponent();         }          private void Button_GetToken_Click(object sender, EventArgs e)         {             AuthorizationForm GetToken = new AuthorizationForm();             GetToken.ShowDialog();         }          private void MainForm_Load(object sender, EventArgs e)         {             try             {                 StreamReader ControlInf = new StreamReader(&quot;UserInf.txt&quot;);                 _Token = ControlInf.ReadLine();                 _UserId = ControlInf.ReadLine();                 ControlInf.Close();                 if (_Token != null)                 {                     _ApiRequest = new VkAPI(_Token);                     string[] Params = { &quot;city&quot;, &quot;country&quot;, &quot;photo_max&quot; };                     _Response = _ApiRequest.GetInformation(_UserId, Params);                     if (_Response != null)                     {                         User_ID.Text = _UserId;                         User_Photo.ImageLocation = _Response[&quot;photo_max&quot;];                         User_Name.Text = _Response[&quot;first_name&quot;];                         User_Surname.Text = _Response[&quot;last_name&quot;];                         User_Country.Text = _ApiRequest.GetCountryById(_Response[&quot;country&quot;]);                         User_City.Text = _ApiRequest.GetCityById(_Response[&quot;city&quot;]);                         Button_GetToken.Visible = false;                     }                 }             }             catch{}         }          private void Button_GetInformation_Click(object sender, EventArgs e)         {             try             {                 StreamReader ControlInf = new StreamReader(&quot;UserInf.txt&quot;);                 _Token = ControlInf.ReadLine();                 ControlInf.Close();                 _ApiRequest = new VkAPI(_Token);                 _UserId = User_ID.Text;                 string[] Params = { &quot;city&quot;, &quot;country&quot;, &quot;photo_max&quot; };                 _Response = _ApiRequest.GetInformation(_UserId, Params);                 if (_Response != null)                 {                     User_ID.Text = _UserId;                     User_Photo.ImageLocation = _Response[&quot;photo_max&quot;];                     User_Name.Text = _Response[&quot;first_name&quot;];                     User_Surname.Text = _Response[&quot;last_name&quot;];                     User_Country.Text = _ApiRequest.GetCountryById(_Response[&quot;country&quot;]);                     User_City.Text = _ApiRequest.GetCityById(_Response[&quot;city&quot;]);                     Button_GetToken.Visible = false;                 }             }             catch             {              }         }     } } <\/code><\/pre>\n<p>  \u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043a\u043e\u0434:<\/p>\n<p>  \u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d \u0438 ID \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f:<\/p>\n<pre><code class=\"cs\">StreamReader ControlInf = new StreamReader(&quot;UserInf.txt&quot;); _Token = ControlInf.ReadLine(); _UserId = ControlInf.ReadLine(); ControlInf.Close(); <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0448\u043b\u043e \u0443\u0441\u043f\u0435\u0448\u043d\u043e, \u0442\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 (\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0442\u043e\u043a\u0435\u043d\u0430 \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u044c):<\/p>\n<pre><code class=\"cs\">_ApiRequest = new VkAPI(_Token); string[] Params = { &quot;city&quot;, &quot;country&quot;, &quot;photo_max&quot; }; _Response = _ApiRequest.GetInformation(_UserId, Params); <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u0443\u0441\u043f\u0435\u0448\u0435\u043d, \u0442\u043e \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0432 \u0444\u043e\u0440\u043c\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0438 \u043a\u043d\u043e\u043f\u043a\u0430 GetToken \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439:<\/p>\n<pre><code class=\"cs\">User_ID.Text = _UserId; User_Photo.ImageLocation = _Response[&quot;photo_max&quot;]; User_Name.Text = _Response[&quot;first_name&quot;]; User_Surname.Text = _Response[&quot;last_name&quot;]; User_Country.Text = _ApiRequest.GetCountryById(_Response[&quot;country&quot;]); User_City.Text = _ApiRequest.GetCityById(_Response[&quot;city&quot;]); Button_GetToken.Visible = false; <\/code><\/pre>\n<p>  \u0418\u043d\u0430\u0447\u0435 \u043a\u043d\u043e\u043f\u043a\u0430 GetToken \u0430\u043a\u0442\u0438\u0432\u043d\u0430, \u0438 \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043d\u0435\u0451 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f:<\/p>\n<pre><code class=\"cs\"> private void Button_GetInformation_Click(object sender, EventArgs e)         {             try             {                 StreamReader ControlInf = new StreamReader(&quot;UserInf.txt&quot;);                 _Token = ControlInf.ReadLine();                 ControlInf.Close();                 _ApiRequest = new VkAPI(_Token);                 _UserId = User_ID.Text;                 string[] Params = { &quot;city&quot;, &quot;country&quot;, &quot;photo_max&quot; };                 _Response = _ApiRequest.GetInformation(_UserId, Params);                 if (_Response != null)                 {                     User_ID.Text = _UserId;                     User_Photo.ImageLocation = _Response[&quot;photo_max&quot;];                     User_Name.Text = _Response[&quot;first_name&quot;];                     User_Surname.Text = _Response[&quot;last_name&quot;];                     User_Country.Text = _ApiRequest.GetCountryById(_Response[&quot;country&quot;]);                     User_City.Text = _ApiRequest.GetCityById(_Response[&quot;city&quot;]);                     Button_GetToken.Visible = false;                 }             }             catch             {              }         } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 GET-\u0437\u0430\u043f\u0440\u043e\u0441. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f:<\/p>\n<pre><code class=\"cs\">HttpRequest GetInformation = new HttpRequest(); <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0432 \u043d\u0435\u0451 \u0437\u0430\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<pre><code class=\"cs\">GetInformation.AddUrlParam(&quot;user_ids&quot;, UserId); GetInformation.AddUrlParam(&quot;access_token&quot;, _Token); string Params = &quot;&quot;; foreach (string i in Fields) {     Params += i + &quot;,&quot;; } Params = Params.Remove(Params.Length - 1); GetInformation.AddUrlParam(&quot;fields&quot;, Params); <\/code><\/pre>\n<p>  \u0418 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f GET-\u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"cs\">string Result = GetInformation.Get(__VKAPIURL + &quot;users.get&quot;).ToString(); <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0431\u0440\u0435\u0437\u0430\u0435\u0442\u0441\u044f \u0434\u043e \u0441\u0442\u0440\u043e\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"cs\">Result = Result.Substring(13, Result.Length - 15); <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u044f json \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c:<\/p>\n<pre><code class=\"cs\">Dictionary&lt;string, string&gt; Dict = JsonConvert.DeserializeObject&lt;Dictionary&lt;string, string&gt;&gt;(Result); <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0433\u043e\u0442\u043e\u0432\u043e! \u0425\u043e\u0442\u044c \u043e\u043d\u043e \u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435, \u043d\u043e \u043e\u043d\u043e \u0434\u0430\u0451\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 API \u00ab\u0412\u041a\u043e\u043d\u0442\u0430\u043a\u0442\u0435\u00bb \u043d\u0430 C#. \u0412\u0441\u0435\u043c \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u042f \u0433\u043e\u0442\u043e\u0432 \u0432\u044b\u0441\u043b\u0443\u0448\u0430\u0442\u044c \u0432\u0430\u0448\u0438 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f.<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/314518\/\"> https:\/\/habrahabr.ru\/post\/314518\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0442\u0435\u0431\u044f, \u0434\u043e\u0440\u043e\u0433\u043e\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c! \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u043c \u0434\u043b\u044f \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432, \u0432 \u043d\u0435\u0439 \u043e\u043f\u0438\u0441\u0430\u043d \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0433\u043e WindowsForms \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 API \u0441\u043e\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u00ab\u0412\u041a\u043e\u043d\u0442\u0430\u043a\u0442\u0435\u00bb. \u041d\u043e \u044d\u0442\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 (VK.Net \u0438 \u043f\u0440\u043e\u0447\u0438\u0435) \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a API VK.<\/p>\n<p>  <b>\u0417\u0430\u0434\u0430\u0447\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:<\/b><\/p>\n<ol>\n<li>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c User Token \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0432\u0441\u0435 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0433\u043e.<\/li>\n<li>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430 \u0432\u0445\u043e\u0434 ID \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/li>\n<li>\u0412\u044b\u0432\u0435\u0441\u0442\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 \u0441 \u0432\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u043c ID.<\/li>\n<\/ol>\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-280503","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/280503","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=280503"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/280503\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=280503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=280503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=280503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}