{"id":344024,"date":"2023-01-16T21:02:33","date_gmt":"2023-01-16T21:02:33","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=344024"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=344024","title":{"rendered":"<span>Unity3d: \u0417\u0430\u043f\u0438\u0441\u044c \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 Yandex \u0434\u0438\u0441\u043a \u043d\u0430 C#<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041a \u043c\u043e\u0435\u043c\u0443 \u0443\u0434\u0438\u0432\u043b\u0435\u043d\u0438\u044e, \u043d\u0430 \u0441\u0442\u043e\u043b\u044c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u0430\u043a \u042f\u043d\u0434\u0435\u043a\u0441 \u0434\u0438\u0441\u043a, \u043d\u0435 \u043d\u0430\u0448\u043b\u043e\u0441\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0438 \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 \u0434\u0438\u0441\u043a \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f C#. \u041d\u0430 PHP \u0436\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u0430\u044f, \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432\u0434\u043e\u0432\u043e\u043b\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: <a href=\"https:\/\/snipp.ru\/php\/disk-yandex\" rel=\"noopener noreferrer nofollow\">https:\/\/snipp.ru\/php\/disk-yandex<\/a><\/p>\n<p>\u042f, \u043a\u0430\u043a \u0447\u0435\u043b\u043e\u0432\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u0438\u0437\u0443\u0447\u0430\u043b \u0432\u0435\u0431, \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043b \u0441\u0443\u0442\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043a \u0447\u0435\u043c\u0443. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u044d\u0442\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0451 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435: <a href=\"https:\/\/oauth.yandex.ru\/\" rel=\"noopener noreferrer nofollow\">https:\/\/oauth.yandex.ru\/<\/a> \u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u043d\u0435\u0442, \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u0434\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f REST API \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u0434\u0438\u0441\u043a\u0443.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u044b \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438\u0441\u044c, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043a\u043e\u0434 ClientID OAuth. \u041e\u043d \u0442\u043e \u043d\u0430\u0441 \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c78\/baa\/01d\/c78baa01dae5d7dae4ba60e34562f981.png\" width=\"1841\" height=\"483\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c78\/baa\/01d\/c78baa01dae5d7dae4ba60e34562f981.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430:<br \/>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435, \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u044f \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0432 \u043d\u0435\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 OAuth.<br \/><a href=\"https:\/\/oauth.yandex.ru\/authorize?response_type=token&amp;client_id=\" rel=\"noopener noreferrer nofollow\">https:\/\/oauth.yandex.ru\/authorize?response_type=token&amp;client_id=<\/a>&lt;\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (OAuth)><\/p>\n<p>\u0412\u0430\u043c \u0432\u044b\u0434\u0430\u0441\u0442\u0441\u044f \u043a\u043e\u0434 &#8212; \u0442\u043e\u043a\u0435\u043d.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u043d\u0430 \u0434\u0438\u0441\u043a, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c 2 http \u0437\u0430\u043f\u0440\u043e\u0441\u0430. GET \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f url, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043b\u0438\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u0444\u0430\u0439\u043b \u0438 PUT \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430. <br \/>(\u041e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/yandex.ru\/dev\/disk\/api\/reference\/upload.html#response-upload\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0447\u0435\u0441\u0442\u044c \u0432 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>).<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435, \u044f \u0437\u0430\u0445\u043e\u0442\u0435\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0434\u0438\u0441\u043a\u0435, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0444\u0430\u0439\u043b. \u0412\u0441\u0451 \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<pre><code class=\"cs\">using UnityEngine; using System.Net; using System.Net.Http; public class BackUpOnYandex : MonoBehaviour {     [Header(\"\u041e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d\")]     public string token = \"\";     [Header(\"\u041f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u043d\u0430 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0435\")]     public string path = \"\";     [Header(\"\u041f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u043d\u0430 \u0434\u0438\u0441\u043a\u0435\")]     public string path_disk = \"\";      [Button(nameof(SaveAsync))]     public bool buttonField;     public async System.Threading.Tasks.Task SaveAsync()     {         await testAsync();         await testAsync2();     }      public async System.Threading.Tasks.Task testAsync()     {\/\/\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0434\u0438\u0441\u043a\u0435         HttpClient client = new HttpClient();          HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, \"https:\/\/cloud-api.yandex.net\/v1\/disk\");          request.Headers.Add(\"Accept\", \"application\/json\");         request.Headers.Add(\"Authorization\", $\"OAuth {token}\");          HttpResponseMessage response = await client.SendAsync(request);         response.EnsureSuccessStatusCode();         string responseBody = await response.Content.ReadAsStringAsync();         Debug.Log(\"\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0434\u0438\u0441\u043a\u0435\");         Debug.Log(responseBody);      }     public async System.Threading.Tasks.Task testAsync2()     {\/\/\u0441\u0441\u044b\u043b\u043a\u0430 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0444\u0430\u0439\u043b\u0430         HttpClient client = new HttpClient();          HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, \"https:\/\/cloud-api.yandex.net\/v1\/disk\/resources\/upload?path=\" + path_disk + \"&amp;overwrite=true\");          request.Headers.Add(\"Accept\", \"application\/json\");         request.Headers.Add(\"Authorization\", $\"OAuth {token}\");          HttpResponseMessage response = await client.SendAsync(request);         response.EnsureSuccessStatusCode();         string responseBody = await response.Content.ReadAsStringAsync();         Debug.Log(\"\u041f\u0440\u0438\u0448\u0435\u0434\u0448\u0438\u0439 JSON:\");         Debug.Log(responseBody);         int indexOfSubstring = responseBody.IndexOf(\"https\");         responseBody = responseBody.Substring(indexOfSubstring);         int indexOfSubstring2 = responseBody.IndexOf(\"\\\"\");         responseBody = responseBody.Substring(0, indexOfSubstring2);         Debug.Log(\"\u0421\u0441\u044b\u043b\u043a\u0430 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0444\u0430\u0439\u043b\u0430:\" + responseBody);         HTTP_PUT(responseBody, path);      }      \/\/ HTTP_PUT Function \u041c\u0435\u0442\u043e\u0434 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 url     public void HTTP_PUT(string Url, string filePath)     {         Debug.Log(\"\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0444\u0430\u0439\u043b POST \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c\");         using (WebClient client = new WebClient())         {             client.UploadFile(Url, filePath);         }         Debug.Log(\"\u0417\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043e\");     } }<\/code><\/pre>\n<p>\u0412 \u0441\u043a\u0440\u0438\u043f\u0442\u0435 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043a\u043d\u043e\u043f\u043a\u0438 \u0432 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0435, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0435 \u0433\u0434\u0435-\u0442\u043e \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430:<\/p>\n<pre><code class=\"cs\">using UnityEngine;  #if UNITY_EDITOR using UnityEditor; #endif  #if UNITY_EDITOR [CustomPropertyDrawer(typeof(ButtonAttribute))] public class ButtonDrawer : PropertyDrawer {     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)     {         string methodName = (attribute as ButtonAttribute).MethodName;         Object target = property.serializedObject.targetObject;         System.Type type = target.GetType();         System.Reflection.MethodInfo method = type.GetMethod(methodName);         if (method == null)         {             GUI.Label(position, \"Method could not be found. Is it public?\");             return;         }         if (method.GetParameters().Length > 0)         {             GUI.Label(position, \"Method cannot have parameters.\");             return;         }         if (GUI.Button(position, method.Name))         {             method.Invoke(target, null);         }     } } #endif  public class ButtonAttribute : PropertyAttribute {     public string MethodName { get; }     public ButtonAttribute(string methodName)     {         MethodName = methodName;     } }<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1ae\/ad1\/b48\/1aead1b48ba8f2a11f2a91c3c65b9b05.png\" width=\"551\" height=\"151\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1ae\/ad1\/b48\/1aead1b48ba8f2a11f2a91c3c65b9b05.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043c\u043e\u0433\u043b\u043e 2 \u0441\u0441\u044b\u043b\u043a\u0438:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/yandex.ru\/dev\/disk\/poligon\/\" rel=\"noopener noreferrer nofollow\">\u042f\u043d\u0434\u0435\u043a\u0441 \u043f\u043e\u043b\u0438\u0433\u043e\u043d. \u0421 \u043d\u0435\u0433\u043e \u0431\u0440\u0430\u043b\u043e\u0441\u044c cURL <\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/curlconverter.com\/csharp\/\" rel=\"noopener noreferrer nofollow\">\u041a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440 cURL \u0432 http request \u0421# (\u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e) <\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><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:\/\/habr.com\/ru\/post\/710994\/\"> https:\/\/habr.com\/ru\/post\/710994\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041a \u043c\u043e\u0435\u043c\u0443 \u0443\u0434\u0438\u0432\u043b\u0435\u043d\u0438\u044e, \u043d\u0430 \u0441\u0442\u043e\u043b\u044c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u0430\u043a \u042f\u043d\u0434\u0435\u043a\u0441 \u0434\u0438\u0441\u043a, \u043d\u0435 \u043d\u0430\u0448\u043b\u043e\u0441\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0438 \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 \u0434\u0438\u0441\u043a \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f C#. \u041d\u0430 PHP \u0436\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u0430\u044f, \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432\u0434\u043e\u0432\u043e\u043b\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: <a href=\"https:\/\/snipp.ru\/php\/disk-yandex\" rel=\"noopener noreferrer nofollow\">https:\/\/snipp.ru\/php\/disk-yandex<\/a><\/p>\n<p>\u042f, \u043a\u0430\u043a \u0447\u0435\u043b\u043e\u0432\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u0438\u0437\u0443\u0447\u0430\u043b \u0432\u0435\u0431, \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043b \u0441\u0443\u0442\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043a \u0447\u0435\u043c\u0443. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u044d\u0442\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0451 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435: <a href=\"https:\/\/oauth.yandex.ru\/\" rel=\"noopener noreferrer nofollow\">https:\/\/oauth.yandex.ru\/<\/a> \u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u043d\u0435\u0442, \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u0434\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f REST API \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u0434\u0438\u0441\u043a\u0443.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u044b \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438\u0441\u044c, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043a\u043e\u0434 ClientID OAuth. \u041e\u043d \u0442\u043e \u043d\u0430\u0441 \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430:<br \/>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435, \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u044f \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0432 \u043d\u0435\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 OAuth.<br \/><a href=\"https:\/\/oauth.yandex.ru\/authorize?response_type=token&amp;client_id=\" rel=\"noopener noreferrer nofollow\">https:\/\/oauth.yandex.ru\/authorize?response_type=token&amp;client_id=<\/a>&lt;\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (OAuth)><\/p>\n<p>\u0412\u0430\u043c \u0432\u044b\u0434\u0430\u0441\u0442\u0441\u044f \u043a\u043e\u0434 &#8212; \u0442\u043e\u043a\u0435\u043d.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u043d\u0430 \u0434\u0438\u0441\u043a, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c 2 http \u0437\u0430\u043f\u0440\u043e\u0441\u0430. GET \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f url, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043b\u0438\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u0444\u0430\u0439\u043b \u0438 PUT \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430. <br \/>(\u041e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/yandex.ru\/dev\/disk\/api\/reference\/upload.html#response-upload\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0447\u0435\u0441\u0442\u044c \u0432 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>).<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435, \u044f \u0437\u0430\u0445\u043e\u0442\u0435\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0434\u0438\u0441\u043a\u0435, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0444\u0430\u0439\u043b. \u0412\u0441\u0451 \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<pre><code class=\"cs\">using UnityEngine; using System.Net; using System.Net.Http; public class BackUpOnYandex : MonoBehaviour {     [Header(\"\u041e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d\")]     public string token = \"\";     [Header(\"\u041f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u043d\u0430 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0435\")]     public string path = \"\";     [Header(\"\u041f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u043d\u0430 \u0434\u0438\u0441\u043a\u0435\")]     public string path_disk = \"\";      [Button(nameof(SaveAsync))]     public bool buttonField;     public async System.Threading.Tasks.Task SaveAsync()     {         await testAsync();         await testAsync2();     }      public async System.Threading.Tasks.Task testAsync()     {\/\/\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0434\u0438\u0441\u043a\u0435         HttpClient client = new HttpClient();          HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, \"https:\/\/cloud-api.yandex.net\/v1\/disk\");          request.Headers.Add(\"Accept\", \"application\/json\");         request.Headers.Add(\"Authorization\", $\"OAuth {token}\");          HttpResponseMessage response = await client.SendAsync(request);         response.EnsureSuccessStatusCode();         string responseBody = await response.Content.ReadAsStringAsync();         Debug.Log(\"\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0434\u0438\u0441\u043a\u0435\");         Debug.Log(responseBody);      }     public async System.Threading.Tasks.Task testAsync2()     {\/\/\u0441\u0441\u044b\u043b\u043a\u0430 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0444\u0430\u0439\u043b\u0430         HttpClient client = new HttpClient();          HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, \"https:\/\/cloud-api.yandex.net\/v1\/disk\/resources\/upload?path=\" + path_disk + \"&amp;overwrite=true\");          request.Headers.Add(\"Accept\", \"application\/json\");         request.Headers.Add(\"Authorization\", $\"OAuth {token}\");          HttpResponseMessage response = await client.SendAsync(request);         response.EnsureSuccessStatusCode();         string responseBody = await response.Content.ReadAsStringAsync();         Debug.Log(\"\u041f\u0440\u0438\u0448\u0435\u0434\u0448\u0438\u0439 JSON:\");         Debug.Log(responseBody);         int indexOfSubstring = responseBody.IndexOf(\"https\");         responseBody = responseBody.Substring(indexOfSubstring);         int indexOfSubstring2 = responseBody.IndexOf(\"\\\"\");         responseBody = responseBody.Substring(0, indexOfSubstring2);         Debug.Log(\"\u0421\u0441\u044b\u043b\u043a\u0430 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0444\u0430\u0439\u043b\u0430:\" + responseBody);         HTTP_PUT(responseBody, path);      }      \/\/ HTTP_PUT Function \u041c\u0435\u0442\u043e\u0434 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 url     public void HTTP_PUT(string Url, string filePath)     {         Debug.Log(\"\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0444\u0430\u0439\u043b POST \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c\");         using (WebClient client = new WebClient())         {             client.UploadFile(Url, filePath);         }         Debug.Log(\"\u0417\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043e\");     } }<\/code><\/pre>\n<p>\u0412 \u0441\u043a\u0440\u0438\u043f\u0442\u0435 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043a\u043d\u043e\u043f\u043a\u0438 \u0432 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0435, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0435 \u0433\u0434\u0435-\u0442\u043e \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430:<\/p>\n<pre><code class=\"cs\">using UnityEngine;  #if UNITY_EDITOR using UnityEditor; #endif  #if UNITY_EDITOR [CustomPropertyDrawer(typeof(ButtonAttribute))] public class ButtonDrawer : PropertyDrawer {     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)     {         string methodName = (attribute as ButtonAttribute).MethodName;         Object target = property.serializedObject.targetObject;         System.Type type = target.GetType();         System.Reflection.MethodInfo method = type.GetMethod(methodName);         if (method == null)         {             GUI.Label(position, \"Method could not be found. Is it public?\");             return;         }         if (method.GetParameters().Length > 0)         {             GUI.Label(position, \"Method cannot have parameters.\");             return;         }         if (GUI.Button(position, method.Name))         {             method.Invoke(target, null);         }     } } #endif  public class ButtonAttribute : PropertyAttribute {     public string MethodName { get; }     public ButtonAttribute(string methodName)     {         MethodName = methodName;     } }<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043c\u043e\u0433\u043b\u043e 2 \u0441\u0441\u044b\u043b\u043a\u0438:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/yandex.ru\/dev\/disk\/poligon\/\" rel=\"noopener noreferrer nofollow\">\u042f\u043d\u0434\u0435\u043a\u0441 \u043f\u043e\u043b\u0438\u0433\u043e\u043d. \u0421 \u043d\u0435\u0433\u043e \u0431\u0440\u0430\u043b\u043e\u0441\u044c cURL <\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/curlconverter.com\/csharp\/\" rel=\"noopener noreferrer nofollow\">\u041a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440 cURL \u0432 http request \u0421# (\u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e) <\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><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:\/\/habr.com\/ru\/post\/710994\/\"> https:\/\/habr.com\/ru\/post\/710994\/<\/a><br \/><\/br><\/br><\/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-344024","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/344024","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=344024"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/344024\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=344024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=344024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=344024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}