{"id":284596,"date":"2017-04-07T12:10:06","date_gmt":"2017-04-07T08:10:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=284596"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=284596","title":{"rendered":"Unity3d \/ Android: \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435 Node.JS"},"content":{"rendered":"<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e android \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432 unity3d, \u043d\u0430 \u0441\u0432\u043e\u0435\u043c node.js \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u0432\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f:<\/p>\n<p>  \u2014 <a href=\"https:\/\/play.google.com\/apps\/publish\/\">\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 GooglePlay<\/a> (\u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0434\u0430\u0436\u0435 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0430\u043b\u044c\u0444\u0430-\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f) <br \/>  \u2014 \u041f\u043b\u0430\u0433\u0438\u043d <a href=\"https:\/\/github.com\/playgameservices\/play-games-plugin-for-unity\/tree\/master\/current-build\">GooglePlayGames for Unity3D<\/a><br \/>  \u2014 \u0414\u043e\u0441\u0442\u0443\u043f \u0432 <a href=\"https:\/\/console.cloud.google.com\/home\/dashboard\">\u043a\u043e\u043d\u0441\u043e\u043b\u044c Google Cloud<\/a><br \/>  \u2014 \u0412\u0430\u0448 <a href=\"https:\/\/nodejs.org\/en\/\">Node.JS-\u0441\u0435\u0440\u0432\u0435\u0440<\/a><br \/>  \u2014 \u041c\u043e\u0434\u0443\u043b\u044c GoogleApis \u0434\u043b\u044f node.js: <code>npm install googleapis --save<\/code><br \/>  <a name=\"habracut\"><\/a><br \/>  \u0415\u0441\u043b\u0438 \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0435\u0449\u0435 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0430\u043b\u044c\u0444\u0430\/\u0431\u0435\u0442\u0430-\u0432\u0435\u0440\u0441\u0438\u0438 \u0432 GooglePlay \u2014 \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u0432 \u0430\u043a\u043a\u0430\u0443\u043d\u0442, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0435\u0441\u044c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0422\u0430\u043a\u0436\u0435 \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043e \u0432 \u0418\u0433\u0440\u043e\u0432\u044b\u0445 \u0421\u0435\u0440\u0432\u0438\u0441\u0430\u0445.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/drive.google.com\/a\/cryonis.com\/uc?export=view&amp;id=0B3lk1Amsx1qUazBSS0o0MHpnb3c\" alt=\"image\"\/><\/p>\n<h3>\u041a\u043b\u0438\u0435\u043d\u0442<\/h3>\n<p>  \u0420\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0432 unity3d \u043f\u043b\u0430\u0433\u0438\u043d GooglePlayForUnity3d. \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c Window\/ GooglePlayGames\/Setup\/Android Setup.<\/p>\n<p>  \u041f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u043f\u043e\u043b\u044f \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439. \u0414\u043b\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u043e Resources Definition \u2014 \u0438\u0434\u0435\u043c \u0432 <a href=\"https:\/\/play.google.com\/apps\/publish\/\">\u043a\u043e\u043d\u0441\u043e\u043b\u044c GooglePlay<\/a>, \u0440\u0430\u0437\u0434\u0435\u043b \u0418\u0433\u0440\u043e\u0432\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u0414\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f. \u0412\u0432\u043e\u0434\u0438\u043c \u043c\u0438\u043d\u0438\u043c\u0443\u043c 5 \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u0439 (\u0435\u0441\u043b\u0438 \u0438\u0445 \u043d\u0435\u0442) \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u201c\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b\u201d. \u041d\u0430\u0436\u0438\u043c\u0430\u0435\u043c, \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b Android \u0438 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0432 Unity3d \u0432 \u043f\u043e\u043b\u0435 Resources Definition.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/drive.google.com\/a\/cryonis.com\/uc?export=view&amp;id=0B3lk1Amsx1qUZTBiS0E1WXFVVUk\" alt=\"image\"\/><\/p>\n<p>  \u0412\u043a\u043b\u044e\u0447\u0430\u0435\u043c GooglePlus API. \u0412 \u043f\u043e\u043b\u0435 Web App Client Id \u0432\u0432\u043e\u0434\u0438\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0432\u0438\u0434\u0430 \u0425\u0425\u0425\u0425\u0425\u0425.apps.googleusercontent.com, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 GoogleCloud (\u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u043d\u0438\u0436\u0435).<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/drive.google.com\/a\/cryonis.com\/uc?export=view&amp;id=0B3lk1Amsx1qUektqUzRKNkprV1E\" alt=\"image\"\/><\/p>\n<p>  \u041d\u0430\u0436\u0438\u043c\u0430\u0435\u043c Setup. \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432\u0435\u0440\u0441\u0438\u0439 \u0444\u0430\u0439\u043b\u043e\u0432 \u0441 10.0.1 \u043d\u0430 10.2.0 \u2014 \u043b\u0443\u0447\u0448\u0435 \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0438 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u201cKeep\u201d.<\/p>\n<p>  \u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435 \u2014 \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0432 \u043f\u0430\u043f\u043a\u0435 Plugins\/Android \u0435\u0441\u0442\u044c \u0444\u0430\u0439\u043b\u044b sdk (*.aar) \u0432\u0435\u0440\u0441\u0438\u0438 \u0432\u044b\u0448\u0435 10.0.1 \u2014 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u0435 \u0438\u0445 \u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u044e 10.0.1 \u2014 \u043d\u0430\u0439\u0442\u0438 \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0432 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0443 \u0432\u0430\u0441 sdk (sdk\\extras\\google\\m2repository\\com\\google\\android\\gms\\) \u2014 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0448\u0430\u0433 \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0434\u0430\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439.<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043a\u043b\u0438\u0435\u043d\u0442\u0435 GoogleAuth.cs \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">GoogleAuth.cs<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">using System; using System.Collections; using GooglePlayGames; using GooglePlayGames.BasicApi; using UnityEngine;  public class GoogleAuth:MonoBehaviour {     \/\/\/ &lt;summary&gt;     \/\/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435     \/\/\/ &lt;\/summary&gt;     \/\/\/ &lt;param name=&quot;callback&quot;&gt;&lt;\/param&gt;     public void Auth(Action&lt;string&gt; callback)     {         InitAuth(() =&gt;         {             GetServerToken(callback);         });     }      private void InitAuth(Action callback)     {         var config = new PlayGamesClientConfiguration.Builder()         .AddOauthScope(&quot;profile&quot;)         .AddOauthScope(&quot;email&quot;)         .Build();         PlayGamesPlatform.InitializeInstance(config);         PlayGamesPlatform.Activate();         Social.localUser.Authenticate((success, str) =&gt;         {             if (success)                 callback();             else                 Debug.Log(&quot;Error on Social Authenticate: &quot; + str);         });     }      private void GetServerToken(Action&lt;string&gt; callback)     {         StartCoroutine(ReadToken((serverToken,empty) =&gt;         {             callback(serverToken);         }));     }      private IEnumerator ReadToken(Action&lt;string, string&gt; callback)     {         yield return null;         if (!PlayGamesPlatform.Instance.IsAuthenticated()) \/\/\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f         {             PlayGamesPlatform.Instance.Authenticate((result, msg) =&gt; \/\/\u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0431\u0435\u0437 \u043f\u043e\u043a\u0430\u0437\u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u0438\u0433\u0440\u043e\u043a\u0443             {                 if (!result)                 {                     PlayGamesPlatform.Instance.Authenticate(                         (result2, msg2) =&gt; \/\/\u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0441 \u043f\u043e\u043a\u0430\u0437\u043e\u043c \u043e\u043a\u043d\u0430 googleplay \u0438\u0433\u0440\u043e\u043a\u0443                         {                             if (!result2)                             {                                 PlayGamesPlatform.Instance.GetIdToken(                                     val =&gt; \/\/\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c IdToken \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e                                     {                                         StartCoroutine(ReadToken(callback));                                     });                             }                         }, false);                 }             }, true);         }         else         {                 PlayGamesPlatform.Instance.GetServerAuthCode(                     (status, code) =&gt; \/\/\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u0441\u0432\u043e\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435                     {                         if (status != CommonStatusCodes.Success || string.IsNullOrEmpty(code))                             StartCoroutine(ReadToken(callback));                         else                             callback(code, null);                     });                      }     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u0441\u0446\u0435\u043d\u0435 \u043a \u043a\u0430\u043a\u043e\u043c\u0443-\u043b\u0438\u0431\u043e GameObject.<\/p>\n<p>  \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 Auth \u0441 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d. \u041c\u0435\u0441\u0442\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 GoogleAuth \u2014 \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0438\u0431\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c, \u043b\u0438\u0431\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0438 \u0442.\u043f.<\/p>\n<p>  \u0412 AndroidManifest.xml \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c:<\/p>\n<pre><code class=\"xml\">&lt;uses-permission android:name=&quot;android.permission.GET_ACCOUNTS&quot;\/&gt;   &lt;uses-permission android:name=&quot;android.permission.USE_CREDENTIALS&quot;\/&gt;   &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;\/&gt;   &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot;\/&gt;<\/code><\/pre>\n<p>  <\/p>\n<h3>\u0421\u0435\u0440\u0432\u0435\u0440<\/h3>\n<p>  \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0444\u0430\u0439\u043b \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0434\u043b\u044f GooglePlay. \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0441\u043e\u043b\u044c Cloud Google (https:\/\/console.cloud.google.com\/apis\/credentials?project=\u0438\u0434_\u0432\u0430\u0448\u0435\u0433\u043e_\u043f\u0440\u043e\u0435\u043a\u0442\u0430).<\/p>\n<p>  \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0418\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 OAuth 2.0 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0441 \u0442\u0438\u043f\u043e\u043c \u00ab\u0412\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u00bb. \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0438 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c client-secret (\u0444\u0430\u0439\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f apps.googleusercontent.com.json): <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/drive.google.com\/a\/cryonis.com\/uc?export=view&amp;id=0B3lk1Amsx1qUUlNPWjJ6ZHdsblU\" alt=\"image\"\/><\/p>\n<p>  \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u043f\u0430\u043f\u043a\u0443 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c. \u0423\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432 \u0442\u043e\u043c \u0436\u0435 \u043e\u043a\u043d\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0438 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0443\u044e \u0447\u0430\u0441\u0442\u044c (Unity3d) \u0432 \u043e\u043a\u043d\u0435 GooglePlayGames \u2014 Android configuration \u0432 \u043f\u043e\u043b\u0435 \u00abWeb App Client id\u00bb \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0440\u0430\u043d\u044c\u0448\u0435 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b\u0438 \u043d\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u043c.<\/p>\n<p>  \u041a\u0430\u043a \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u0432\u0430\u0448 \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0435 \u0441\u0442\u043e\u043b\u044c \u0432\u0430\u0436\u043d\u043e, \u0442\u0443\u0442 \u043d\u0430 \u0432\u0430\u0448 \u0432\u044b\u0431\u043e\u0440 ( \u0432 \u0442.\u0447. express, websocket, socket.io \u0438 \u0442.\u0434.).<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043e\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">GooglePlayAuth.js<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">&quot;use strict&quot;; const fs = require('fs'); const https = require(&quot;https&quot;); const google = require('googleapis');  \/**  * \u041f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u043c\u0443 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 GoogleCloud  *\/ const _clientSecret = &quot;client_secret.apps.googleusercontent.com.json&quot;; const _userInfoUrl = &quot;https:\/\/www.googleapis.com\/games\/v1\/players\/me&quot;;  let oauth2Client;  \/**  *   *\/ class GooglePlayAuth {     \/**      * \u0415\u0434\u0438\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f      * @param callback      *\/     static Init(callback) {         fs.readFile(_clientSecret, function (err, content) {             if (err) {                 callback(err);                 return;             }             const credentials = JSON.parse(content);             oauth2Client = new google.auth.OAuth2(credentials.web.client_id, credentials.web.client_secret, credentials.web.redirect_uris[0]);             callback(null);         });     }     \/**      * \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f       * @param serverToken      * @param callback      *\/     static Verify(serverToken,callback) {         oauth2Client.getToken(serverToken, function (err, token) {             if (err) {                 callback(`Error while retrieve access token: ${err}`);                 return;             }             oauth2Client.credentials = token;             \/\/\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435             require(&quot;https&quot;).get(`${_userInfoUrl}?access_token=${token.access_token}`, function (res) {                 res.on(&quot;data&quot;, function (d) {                     let userData = {};                     try {                         userData = JSON.parse(d);                     } catch (er) {                         callback(`Error parse user data ${er}`);                         return;                     }                     if (userData.playerId == null) {                         callback(`Error read playerId: ${userData}`);                         return;                     }                     \/\/\u0432\u0441\u0435 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 - \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043c\u043e\u0434\u0443\u043b\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f                     callback(null, userData);                 });             }).on(&quot;error&quot;, function (err) {                 callback(`Fail request: ${err}`);             });         });     } }  module.exports = GooglePlayAuth; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0432\u044b\u0437\u0432\u0430\u0442\u044c GooglePlayAuth.Init.<\/p>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0432 GooglePlayAuth.Verify, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0435\u0440\u043d\u0435\u0442 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u043b\u0438\u0431\u043e \u043e\u0448\u0438\u0431\u043a\u0443, \u043b\u0438\u0431\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043e\u0442 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 Google.<\/p>\n<p>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<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\/325900\/\"> https:\/\/habrahabr.ru\/post\/325900\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e android \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432 unity3d, \u043d\u0430 \u0441\u0432\u043e\u0435\u043c node.js \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u0432\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f:<\/p>\n<p>  \u2014 <a href=\"https:\/\/play.google.com\/apps\/publish\/\">\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 GooglePlay<\/a> (\u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0434\u0430\u0436\u0435 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0430\u043b\u044c\u0444\u0430-\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f) <br \/>  \u2014 \u041f\u043b\u0430\u0433\u0438\u043d <a href=\"https:\/\/github.com\/playgameservices\/play-games-plugin-for-unity\/tree\/master\/current-build\">GooglePlayGames for Unity3D<\/a><br \/>  \u2014 \u0414\u043e\u0441\u0442\u0443\u043f \u0432 <a href=\"https:\/\/console.cloud.google.com\/home\/dashboard\">\u043a\u043e\u043d\u0441\u043e\u043b\u044c Google Cloud<\/a><br \/>  \u2014 \u0412\u0430\u0448 <a href=\"https:\/\/nodejs.org\/en\/\">Node.JS-\u0441\u0435\u0440\u0432\u0435\u0440<\/a><br \/>  \u2014 \u041c\u043e\u0434\u0443\u043b\u044c GoogleApis \u0434\u043b\u044f node.js: <code>npm install googleapis --save<\/code>  <\/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-284596","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284596","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=284596"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284596\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}