{"id":284354,"date":"2017-04-03T14:30:02","date_gmt":"2017-04-03T10:30:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=284354"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=284354","title":{"rendered":"\u0410\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f OAuth2 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c Google Sign-In. \u041d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a API Google"},"content":{"rendered":"<blockquote><p>\u00ab\u0421 20 \u0430\u043f\u0440\u0435\u043b\u044f 2017 \u0433\u043e\u0434\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u0438\u0437 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f\u00bb.<\/p><\/blockquote>\n<p> \u0422\u0430\u043a\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441 1 \u043c\u0430\u0440\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445, \u0433\u0434\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f. \u041e\u0431 \u044d\u0442\u043e\u043c Google \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0432 \u0441\u0432\u043e\u0451\u043c \u0431\u043b\u043e\u0433\u0435 \u0435\u0449\u0435 \u0432 \u0430\u0432\u0433\u0443\u0441\u0442\u0435 2016, \u0438 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0441\u043a\u043e\u0440\u043e \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438. \u041f\u0440\u0438\u044f\u0442\u043d\u043e\u0433\u043e \u043c\u0430\u043b\u043e, \u043e\u0434\u043d\u0430\u043a\u043e \u0432\u044b\u0445\u043e\u0434 \u0435\u0441\u0442\u044c \u2013 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u043c\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 Google Sign-in. <\/p>\n<p>  \u041e\u0431 \u044d\u0442\u043e\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u0435 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u0434\u0442\u0438 \u0440\u0435\u0447\u044c \u0432 \u0443\u0440\u043e\u043a\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u044b, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 API Google. <br \/>  <a name=\"habracut\"><\/a><br \/>  \u0412 \u0443\u0440\u043e\u043a\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0439. \u041d\u043e \u0441\u043f\u0435\u0440\u0432\u0430 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u0438 \u0438\u0437 \u043c\u043e\u0435\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 \u0438 \u043f\u0435\u0440\u0432\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 OAuth2, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043a\u0442\u043e-\u0442\u043e \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0432 \u043f\u043e\u0445\u043e\u0436\u0435\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438. <\/p>\n<p>  \u041f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u043e\u0441\u044c \u043c\u043d\u0435 \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0447\u0430\u0442 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u0438 YouTube. \u0418 \u0442\u043e\u0433\u0434\u0430 \u044f \u0443\u0437\u043d\u0430\u043b\u0430, \u0447\u0442\u043e \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u0438 (\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c \u0447\u0430\u0442\u0430) \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 OAuth2 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u042f \u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0441\u043a\u0430\u0442\u044c. \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u043e \u0442\u0430\u043a\u043e\u0439 \u0442\u0435\u043c\u0435 \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e, \u043e\u043d\u0430 \u0440\u0430\u0437\u0440\u043e\u0437\u043d\u0435\u043d\u0430, \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u043b\u0430 \u0434\u043b\u044f \u043c\u043e\u0435\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f, \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u0432\u0441\u0451 \u0431\u044b\u043b\u043e \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435. \u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0431\u044b\u043b\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 API: Drive, Cloud, Google Plus. \u0412 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 API YouTube \u0435\u0441\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u0434, \u0431\u0435\u0440\u0438 \u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0441\u044f, \u043e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f Android \u043e\u043d \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442. \u041f\u043e\u0442\u0440\u0430\u0442\u0438\u0432 \u043d\u0435\u043c\u0430\u043b\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043f\u0440\u043e\u0431 \u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u044f \u043f\u0440\u0438\u0448\u043b\u0430 \u043a \u0440\u0430\u0431\u043e\u0447\u0435\u043c\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044e. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u043d\u0435 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435, \u044d\u0442\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u00ab\u0432 \u043a\u0443\u0447\u0443\u00bb \u0438 \u0440\u0430\u0437\u043b\u043e\u0436\u0438\u0442\u044c \u043f\u043e \u043f\u043e\u043b\u043e\u0447\u043a\u0430\u043c, \u0447\u0442\u043e \u0438 \u0441\u043f\u043e\u0434\u0432\u0438\u0433\u043b\u043e \u043d\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u0443\u0440\u043e\u043a\u0430. <\/p>\n<p>  \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043c\u043e\u0451 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u043e\u0441\u044c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u043b\u0441\u044f WebView \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 (\u0432\u0432\u043e\u0434 email, \u043f\u0430\u0440\u043e\u043b\u044f). \u0414\u0430\u043b\u0435\u0435 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b \u043a\u043e\u0434 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 (AuthCode), \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0447\u0442\u043e \u0441 \u043d\u0438\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u0434\u0430\u043b\u0435\u0435. Url, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u043b\u0441\u044f \u0432 WebView \u0431\u044b\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439:<\/p>\n<pre><code>https:\/\/accounts.google.com\/o\/oauth2\/auth? client_id=60*********5ad3np.apps.googleusercontent.com &redirect_uri=urn:ietf:wg:oauth:2.0:oob &access_type=offline&response_type=code &scope=https:\/\/www.googleapis.com\/auth\/youtube.readonly<\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043d\u0438 \u0447\u0442\u043e \u0438\u043d\u043e\u0435, \u043a\u0430\u043a post \u0437\u0430\u043f\u0440\u043e\u0441, \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f authCode, \u043f\u0440\u0438\u0447\u0435\u043c \u043a\u043e\u0434 \u0431\u044b\u043b \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b. \u0412\u0441\u0451, \u043a\u0430\u043a \u043f\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438 \u043a API, \u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0434\u043b\u044f \u0441\u043e\u043a\u0440\u044b\u0442\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u043d\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430. <\/p>\n<p>  \u0412\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043e, \u043d\u043e \u0432 \u043e\u0434\u0438\u043d \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u044b\u0439 \u0434\u0435\u043d\u044c \u044f \u0443\u0432\u0438\u0434\u0435\u043b\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/465\/8f5\/b5f\/4658f5b5f1994b669673dee12cbb154e.jpg\" \/><\/div>\n<p>  \u041f\u0435\u0440\u0435\u0439\u0434\u044f \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u00ab\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435\u00bb \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u043c \u0432 \u0431\u043b\u043e\u0433, \u0433\u0434\u0435 \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u0432\u043e \u0438\u043c\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438, \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 WebView \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441 20 \u0430\u043f\u0440\u0435\u043b\u044f. \u041d\u0443 \u0432\u043e\u0442, \u0434\u0443\u043c\u0430\u044e \u044f, \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0434\u0435\u043b\u0430\u043b\u0430 \u0438 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u044b\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 Sign-In. \u041f\u0440\u0438\u0447\u0435\u043c \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u044f \u043f\u044b\u0442\u0430\u043b\u0430\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438\u043c\u0435\u043d\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u044d\u0442\u043e\u0442 \u0441\u0435\u0440\u0432\u0438\u0441. \u041e\u0434\u043d\u0430\u043a\u043e \u0441 \u0443\u0436\u0435 \u0438\u043c\u0435\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u0437\u043d\u0430\u043d\u0438\u044f\u043c\u0438 \u00ab\u0447\u0442\u043e \u0438 \u0437\u0430\u0447\u0435\u043c\u00bb \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e. \u0418 \u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0435\u043c. <\/p>\n<p>  <b>1. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0443\u0447\u0435\u0442\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/b><\/p>\n<p>  \u0412 \u0414\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0435 API \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 (\u0438\u043b\u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439):<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/3d3\/4e1\/4a6\/3d34e14a688e4559a6c7f38ec51dab63.jpg\" \/><\/div>\n<p>  \u0414\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <a href=\"https:\/\/developers.google.com\/mobile\/add?platform=android&amp;cntapi=signin&amp;cnturl=https:%2F%2Fdevelopers.google.com%2Fidentity%2Fsign-in%2Fandroid%2Fsign-in%3Fconfigured%3Dtrue&amp;cntlbl=Continue%20Adding%20Sign-In\">\u0432 \u043c\u0430\u0441\u0442\u0435\u0440\u0435<\/a>:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/7c2\/f88\/703\/7c2f8870335544e99ca6cf1bc35559be.jpg\" \/><\/div>\n<p>  \u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u043e\u043b\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u043f\u0430\u043a\u0435\u0442. \u0414\u0430\u043b\u0435\u0435 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u0430\u043a\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c (Google Sign-In), \u0437\u0434\u0435\u0441\u044c \u043d\u0443\u0436\u043d\u043e \u0432\u0432\u0435\u0441\u0442\u0438 SHA1 \u043a\u043b\u044e\u0447 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e: \u0432 Android Studio \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0432\u043a\u043b\u0430\u0434\u043a\u0443 Gradle, \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0432\u043a\u043b\u0430\u0434\u043a\u0438 Tasks-android-signingReport. \u0429\u0435\u043b\u043a\u0430\u0435\u043c \u0434\u0432\u0430 \u0440\u0430\u0437\u0430, \u0438 \u0432 \u043b\u043e\u0433\u0430\u0445 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043a\u043b\u044e\u0447\u0430\u0445. \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043a\u043b\u044e\u0447 SHA1, \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c. <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/231\/551\/1e6\/2315511e6671456580b3a55447b0782a.jpg\" \/><\/div>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/f65\/a43\/29a\/f65a4329a53b44359410676f3d95a10e.jpg\" \/><\/div>\n<p>  \u0416\u043c\u0435\u043c \u043a\u043d\u043e\u043f\u043a\u0443 \u00abGenerate configuration file\u00bb, \u0430 \u043f\u043e\u0441\u043b\u0435 \u00abDownload google-services.json\u00bb. \u042d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b json \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u043f\u0430\u043f\u043a\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u00abapp\u00bb.<\/p>\n<p>  <b>\u0412\u0430\u0436\u043d\u043e!<\/b> \u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0435\u0441\u044c \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 Google Play, debug \u043a\u043b\u044e\u0447 SHA1 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 release \u043a\u043b\u044e\u0447, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0417\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u0414\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440 API, \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043a\u043b\u044e\u0447\u0438 \u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 OAuth. \u041d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0430\u043d\u043d\u044b\u0435 Web client (\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438 \u0441\u0435\u043a\u0440\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430). <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/3bc\/c80\/b26\/3bcc80b26c5e481c9e70c6f33c43f82d.jpg\"\/><br \/>  \u0412\u043e \u0432\u043a\u043b\u0430\u0434\u043a\u0435 \u00ab\u041e\u043a\u043d\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 OAuth\u00bb \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c email \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 \u2014 \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u00ab\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 **** \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442: \u2026\u00bb <\/p>\n<p>  <b>2. \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 Sign-In \u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/b><\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a Google Api Client, \u0432 \u0444\u0430\u0439\u043b gradle app \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code>compile 'com.google.android.gms:play-services-auth:10.2.0'<\/code><\/pre>\n<p>  \u0418 \u043f\u043b\u0430\u0433\u0438\u043d (\u0432 \u043a\u043e\u043d\u0435\u0446 \u0444\u0430\u0439\u043b\u0430):<\/p>\n<pre><code>apply plugin: 'com.google.gms.google-services'<\/code><\/pre>\n<p>  \u0412 \u0444\u0430\u0439\u043b gradle project \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code>classpath 'com.google.gms:google-services:3.0.0'<\/code><\/pre>\n<p>  \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u043e\u043f\u0446\u0438\u0438:<\/p>\n<pre><code class=\"java\">GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) \t\t\t\t.requestServerAuthCode(getString(R.string.server_client_id)) \t\t\t\t.requestEmail() \t\t\t\t.requestScopes(new Scope(&quot;https:\/\/www.googleapis.com\/auth\/youtube.readonly&quot;)) \t\t\t\t.build();<\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<p>  <code>requestServerAuthCode(getString(R.string.server_client_id))<\/code> \u2013 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c authCode, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 (\u0432\u0435\u0441\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432\u044b\u0448\u0435.<\/p>\n<p>  <code>requestScopes(new Scope(&quot;***&quot;))<\/code> \u2013 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0433\u043e API \u043e\u0431\u043b\u0430\u0441\u0442\u044c\/\u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430. \u0415\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432 Scopes, \u043d\u043e, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e\u0439 \u0442\u0430\u043c \u043d\u0435 \u043d\u0430\u0448\u043b\u043e\u0441\u044c, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u044e, \u043a\u0430\u043a \u0432 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435. \u0414\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u0434\u043e\u0441\u0442\u0443\u043f \u00ab\u043a \u0447\u0435\u043c\u0443\u00bb \u0445\u043e\u0447\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442:<\/p>\n<pre><code class=\"java\">GoogleApiClient mApiClient = new GoogleApiClient.Builder(this) \t\t\t\t.enableAutoManage(this, this) \t\t\t\t.addApi(Auth.GOOGLE_SIGN_IN_API, gso) \t\t\t\t.build();<\/code><\/pre>\n<p>  \u0422\u0443\u0442 \u0432\u0441\u0451 \u043f\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0443 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438:<\/p>\n<p>  <code>enableAutoManage(this, this)<\/code> \u2013 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0430\u043a\u0442\u0438\u0432\u0438\u0442\u0438 \u0438 \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f (\u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 GoogleApiClient.OnConnectionFailedListener).<\/p>\n<p>  <code>addApi(Auth.GOOGLE_SIGN_IN_API, gso)<\/code> \u2013 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Sign In api \u0438 \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u043f\u0446\u0438\u0439.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0430 (\u043b\u0438\u0431\u043e \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442). \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 \u043a\u043d\u043e\u043f\u043a\u0443 Sign In Button. \u0420\u0430\u0437\u043c\u0435\u0442\u043a\u0430 xml:<\/p>\n<pre><code class=\"xml\">&lt;com.google.android.gms.common.SignInButton \t\t\tandroid:id=&quot;@+id\/activity_button_sign_in&quot; \t\t\tandroid:layout_width=&quot;wrap_content&quot; \t\t\tandroid:layout_height=&quot;wrap_content&quot; \/&gt;<\/code><\/pre>\n<p>  \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u043d\u0430 \u0442\u0430\u043a:<\/p>\n<p>  <img decoding=\"async\" height=\"50\" src=\"https:\/\/habrastorage.org\/files\/1e6\/509\/e38\/1e6509e3861f46edaa08510a1ad5a99a.jpg\"\/><\/p>\n<p>  \u0412 \u0430\u043a\u0442\u0438\u0432\u0438\u0442\u0438 \u043a\u043d\u043e\u043f\u043a\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0438 \u0432\u0441\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 view, \u043d\u0430 \u043d\u0435\u0435 \u043f\u043e\u0432\u0435\u0448\u0430\u0435\u043c \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044c \u0438 \u043f\u043e \u043a\u043b\u0438\u043a\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"java\">@Override public void onClick(View view) { \tswitch (view.getId()) { \t\tcase R.id.activity_button_sign_in: \t\t\tsignIn(); \t\t\tbreak; \t} } <\/code><\/pre>\n<p>  \u041a\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u043d\u0442\u0430 \u0438 \u0432\u044b\u0437\u043e\u0432 \u0430\u043a\u0442\u0438\u0432\u0438\u0442\u0438 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"java\">public void signIn() { \t\tIntent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mApiClient); \t\tstartActivityForResult(signInIntent, RC_AUTH_CODE); }<\/code><\/pre>\n<p>  \u0412 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 mApiClient. RC_AUTH_CODE \u043b\u044e\u0431\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u043a\u0430\u043a \u0438 \u0432\u0441\u0435\u0433\u0434\u0430, \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0430\u043a\u0442\u0438\u0432\u0438\u0442\u0438.<\/p>\n<p>  \u041f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043a\u043e\u043f\u043a\u0443, \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0430\u043a\u043a\u0430\u0443\u043d\u0442 \u0434\u043b\u044f \u0432\u0445\u043e\u0434\u0430, \u043b\u0438\u0431\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439. \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u0431\u043e\u0440\u0430, \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" height=\"350\" src=\"https:\/\/habrastorage.org\/files\/806\/185\/fc1\/806185fc18ee4b2b87f07de434fbfece.jpg\" \/><\/div>\n<p>  <b>3. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 Auth code<\/b><\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0434\u0430\u0441\u0442 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0432 onActivityResult \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0435\u0433\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430:<\/p>\n<pre><code class=\"java\">@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { \tif (requestCode == RC_AUTH_CODE) { \t\tGoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); \t\tif (result.isSuccess()) { \t\t\tGoogleSignInAccount acct = result.getSignInAccount(); \t\t\tString authCode = acct.getServerAuthCode(); \t\t\tgetAccessToken(authCode); \t\t}  \t} } <\/code><\/pre>\n<p>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c auth code \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u043d \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code>4\/iHhVmqtxccXh0Qs*********oo5XG8OjaNsWu_kEKyw<\/code><\/pre>\n<p>  \u0422\u0430\u043a \u0436\u0435 \u0438\u0437 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c email \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, username \u0438 \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0443:<\/p>\n<p>  acct.getEmail()<br \/>  acct.getDisplayName()<br \/>  acct.getPhotoUrl() <\/p>\n<p>  \u042d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u0445 \u0432 header NavigationView.<\/p>\n<p>  <b>4. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 Access Token \u0438 Refresh Token<\/b><\/p>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 auth code, \u0442\u0435\u043f\u0435\u0440\u044c \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a API \u0442\u043e\u043a\u0435\u043d\u044b. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <code>https:\/\/www.googleapis.com\/oauth2\/v4\/token.<\/code> \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u044f \u0441\u0434\u0435\u043b\u0430\u044e \u044d\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e OkHttp. <\/p>\n<pre><code class=\"java\">public void getAccessToken(String authCode) { \tOkHttpClient client = new OkHttpClient(); \tRequestBody requestBody = new FormEncodingBuilder() \t\t\t.add(&quot;grant_type&quot;, &quot;authorization_code&quot;) \t\t\t.add(&quot;client_id&quot;, getString(R.string.server_client_id)) \t\t\t.add(&quot;client_secret&quot;, getString(R.string.client_secret)) \t\t\t.add(&quot;code&quot;, authCode) \t\t\t.build(); \tfinal Request request = new Request.Builder() \t\t\t.url(&quot;https:\/\/www.googleapis.com\/oauth2\/v4\/token&quot;) \t\t\t.header(&quot;Content-Type&quot;, &quot;application\/x-www-form-urlencoded&quot;) \t\t\t.post(requestBody) \t\t\t.build(); \tclient.newCall(request).enqueue(new Callback() { \t\t@Override \t\tpublic void onFailure(Request request, IOException e) {} \t\t@Override \t\tpublic void onResponse(Response response) throws IOException { \t\t\ttry { \t\t\t\tJSONObject jsonObject = new JSONObject(response.body().string()); \t\t\t\tmAccessToken = jsonObject.get(&quot;access_token&quot;).toString(); \t\t\t\tmTokenType = jsonObject.get(&quot;token_type&quot;).toString(); \t\t\t\tmRefreshToken = jsonObject.get(&quot;refresh_token&quot;).toString(); \t\t\t} catch (JSONException e) { \t\t\t\te.printStackTrace(); \t\t\t} \t\t} \t}); }<\/code><\/pre>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b. \u0412 Request.Builder() \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c url \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d\u044b:<\/p>\n<pre><code>url(&quot;https:\/\/www.googleapis.com\/oauth2\/v4\/token&quot;)<\/code><\/pre>\n<p>  \u0412 header \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c Content-Type:<\/p>\n<pre><code>header(&quot;Content-Type&quot;, &quot;application\/x-www-form-urlencoded&quot;)<\/code><\/pre>\n<p>  \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 POST, \u0432 \u043d\u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c body:<\/p>\n<pre><code>post(requestBody)<\/code><\/pre>\n<p>  \u0421\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 requestBody \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<p>  <code>&quot;grant_type&quot;, &quot;authorization_code&quot;<\/code> \u2013 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c auth code<br \/>  <code>&quot;client_id&quot;, getString(R.string.server_client_id)<\/code> \u2013 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f client id, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0432 \u0414\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0435 API<br \/>  <code>&quot;client_secret&quot;, getString(R.string.client_secret)<\/code> \u2014 \u0441\u0435\u043a\u0440\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0432 \u0414\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0435 API<br \/>  <code>&quot;code&quot;, authCode<\/code> \u2013 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<p>  \u0417\u0430\u043f\u0440\u043e\u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439, \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 json \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u043d\u0443\u0436\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0434\u0430\u043d\u043d\u044b\u043c\u0438:<\/p>\n<pre><code>{ &quot;access_token&quot;:&quot;ya29.GlsfBJNMTfGy\u2026&quot;, &quot;token_type&quot;:&quot;Bearer&quot;, &quot;expires_in&quot;:3600, &quot;refresh_token&quot;:&quot;1\\\/72OqA7zYuyY__XhGij5oA2nEb7\u2026&quot;, &quot;id_token&quot;:&quot;eyJhbGciOiJSUzI1NiIsImtpZ\u2026&quot; }<\/code><\/pre>\n<p>  <code>&quot;access_token&quot;<\/code> \u2013 \u0442\u043e\u043a\u0435\u043d \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u0440\u0430\u0434\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u0441\u0451 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u043e\u0441\u044c<br \/>  <code>&quot;expires_in&quot;<\/code> \u2013 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 access \u0442\u043e\u043a\u0435\u043d\u0430, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0442\u043e\u043a\u0435\u043d \u0436\u0438\u0432\u0435\u0442 1 \u0447\u0430\u0441, \u0430 \u0432 \u0441\u0443\u0442\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043f\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0443 25 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u043d\u0435 \u0431\u043e\u043b\u0435\u0435. <br \/>  <code>&quot;token_type&quot;<\/code> \u2013 \u0442\u0438\u043f \u0442\u043e\u043a\u0435\u043d\u0430, \u0435\u0433\u043e \u0442\u043e\u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u043e\u043d \u0442\u0430\u043a\u0436\u0435 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a api \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c.<br \/>  <code>&quot;refresh_token&quot;<\/code> \u2013 \u0442\u043e\u043a\u0435\u043d \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f access \u0442\u043e\u043a\u0435\u043d\u0430, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u0447\u0430\u0441 \u0436\u0438\u0437\u043d\u0438. Refresh \u0442\u043e\u043a\u0435\u043d \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u0435\u043d. \u0427\u0430\u0441\u0442\u043e \u043d\u0430 \u0444\u043e\u0440\u0443\u043c\u0430\u0445 \u0432\u0438\u0434\u0435\u043b\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0430\u0441\u044c \u0438 \u0441\u0430\u043c\u0430: \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b \u044d\u0442\u043e\u0442 \u0442\u043e\u043a\u0435\u043d. \u041e\u0448\u0438\u0431\u043a\u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u0432 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0443\u0447\u0435\u0442\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043b\u0438\u0431\u043e \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0415\u0441\u043b\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u0430\u0441\u044c \u0447\u0435\u0440\u0435\u0437 WebView, \u0438 \u0432 url \u043d\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u0432\u0430\u0436\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043a\u0430\u043a access_type=offline, \u0442\u043e refresh \u0442\u043e\u043a\u0435\u043d \u043f\u043e\u043f\u0440\u043e\u0441\u0442\u0443 \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b.<\/p>\n<p>  <b>5. \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 Access \u0442\u043e\u043a\u0435\u043d\u0430<\/b><\/p>\n<p>  \u0427\u0430\u0441 \u043f\u0440\u043e\u0448\u0435\u043b, access \u0442\u043e\u043a\u0435\u043d \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0430\u043a\u0442\u0438\u0432\u0435\u043d, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u044b\u043f\u044f\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0438 401 \u0438\u043b\u0438 403, \u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u043a\u0430\u0436\u0435\u0442, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u0438\u043b\u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430. \u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u043e\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435 \u0433\u043e\u0434\u0438\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u0430\u044f \u0441\u0435\u0441\u0441\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u043a \u0443 \u043c\u0435\u043d\u044f, \u043d\u0443\u0436\u043d\u043e \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438\u0437 \u0447\u0430\u0442\u0430 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u0438, \u0430 \u044d\u0442\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u043e\u0432. \u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c? \u041f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430. <\/p>\n<p>  \u0417\u0430\u043f\u0440\u043e\u0441 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u043a\u0430\u043a \u0432 \u043f\u0443\u043d\u043a\u0442\u0435 4, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432:<\/p>\n<pre><code class=\"java\">private void getNewAccessToken() { \tOkHttpClient client = new OkHttpClient(); \tRequestBody requestBody = new FormEncodingBuilder() \t\t\t\t.add(&quot;refresh_token&quot;, mRefreshToken) \t\t\t\t.add(&quot;client_id&quot;, getString(R.string.server_client_id)) \t\t\t        .add(&quot;client_secret&quot;, getString(R.string.client_secret)) \t\t\t\t.add(&quot;grant_type&quot;, &quot;refresh_token&quot;) \t\t\t\t.build(); \tfinal Request request = new Request.Builder() \t\t\t\t.url(&quot;https:\/\/www.googleapis.com\/oauth2\/v4\/token&quot;) \t\t\t\t.header(&quot;Content-Type&quot;, &quot;application\/x-www-form-urlencoded&quot;) \t\t\t\t.post(requestBody) \t\t\t\t.build(); \tclient.newCall(request).enqueue(new Callback() { \t\t@Override \t\tpublic void onFailure(Request request, IOException e) {} \t\t@Override \t\tpublic void onResponse(Response response) throws IOException { \t\t\ttry { \t\t\t\tJSONObject jsonObject = new JSONObject(response.body().string()); \t\t\t\tmAccessToken = jsonObject.get(&quot;access_token&quot;).toString(); \t\t\t} catch (JSONException e) { \t\t\t\te.printStackTrace(); \t\t\t} \t\t} \t}); }<\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0432\u0430\u0436\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<p>  <code>&quot;grant_type&quot;, &quot;refresh_token&quot;<\/code> \u2013 \u0432 \u0442\u0438\u043f\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0447\u0442\u043e \u043f\u043e\u0441\u044b\u043b\u0430\u0435\u043c refresh \u0442\u043e\u043a\u0435\u043d<br \/>  <code>&quot;refresh_token&quot;, mRefreshToken<\/code> \u2013 \u0438 \u0441\u0430\u043c \u0442\u043e\u043a\u0435\u043d<\/p>\n<p>  \u041e\u0442\u0432\u0435\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 json, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043d\u043e\u0432\u044b\u0439 access \u0442\u043e\u043a\u0435\u043d, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u043d\u043e\u0432\u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a API:<\/p>\n<pre><code>{ &quot;access_token&quot;:&quot;ya29.GlsfBM7Y...&quot;, &quot;token_type&quot;:&quot;Bearer&quot;, &quot;expires_in&quot;:3600, &quot;id_token&quot;:&quot;eyJhbGciOiJ...&quot; }<\/code><\/pre>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430.<\/p>\n<p>  \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a API, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u043a \u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u0430.<br \/>  \u0414\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a API \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e Retrofit2 + RxAndroid. \u0422\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0447\u0430\u0442\u0430 \u043f\u0440\u044f\u043c\u043e\u0439 \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u0438:<\/p>\n<pre><code class=\"java\">@GET(GoogleApiUrls.Youtube.CHAT) Observable&lt;ChatResponse&gt; getChat(@Header(&quot;Authorization&quot;) String token, @Query(&quot;liveChatId&quot;) String liveChatId, @Query(&quot;part&quot;) String part);<\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0432\u0430\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 header \u043f\u043e \u043a\u043b\u044e\u0447\u0443 Authorization \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0438\u043f \u0442\u043e\u043a\u0435\u043d\u0430 \u0438 \u0441\u0430\u043c access \u0442\u043e\u043a\u0435\u043d. \u0422\u043e \u0435\u0441\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code>Authorization Bearer ya29.GlsfBJNMTfGy\u2026<\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0434\u0435\u043b\u0430\u044e \u0437\u0430\u043f\u0440\u043e\u0441 \u0447\u0435\u0440\u0435\u0437 RxAndroid, \u0438 \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u043a\u043e\u043b\u043b\u0431\u044d\u043a onError \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0432\u0441\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u0442\u043e \u0442\u0443\u0434\u0430 \u0436\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 HttpException \u0441 \u043a\u043e\u0434\u043e\u043c 401 Unauthorized \u043f\u043e \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u0447\u0430\u0441\u0430. \u0417\u0434\u0435\u0441\u044c \u0436\u0435 \u044f \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e \u0435\u0451, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0442\u0430 \u0441\u0430\u043c\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430, \u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443 \u0442\u0438\u043f\u0443, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0438 \u044d\u0442\u043e \u043a\u043e\u0434 401 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430, \u0437\u0430\u0442\u0435\u043c \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e \u0437\u0430\u043f\u0440\u043e\u0441. <\/p>\n<pre><code class=\"java\">@Override public void onError(Throwable e) { \tif (e instanceof HttpException) { \t\tHttpException exception = (HttpException) e; \t\tif (exception.code() == 401) { \t\t\tgetNewAccessToken(); \t\t} \t} }<\/code><\/pre>\n<p>  \u0422\u0430\u043a \u0436\u0435 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u043e\u043a\u0435\u043d\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 GET \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code>https:\/\/www.googleapis.com\/oauth2\/v3\/tokeninfo?access_token=ya29.GlsfBJNMTfGy\u2026<\/code><\/pre>\n<p>  \u0412 \u043e\u0442\u0432\u0435\u0442 \u043f\u0440\u0438\u0434\u0443\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0442\u043e\u043a\u0435\u043d\u0435, \u0435\u0441\u043b\u0438 \u043e\u043d \u0435\u0449\u0435 \u0430\u043a\u0442\u0438\u0432\u0435\u043d, \u043b\u0438\u0431\u043e \u043e\u0448\u0438\u0431\u043a\u0430, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0438\u0441\u0442\u0435\u043a\u043b\u043e. <\/p>\n<p>  \u041e\u043f\u044f\u0442\u044c \u0436\u0435, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0430 Google \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430.<\/p>\n<p>  \u0412\u044b\u0439\u0442\u0438 \u0438\u0437 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u0438 \u043e\u0442\u043e\u0437\u0432\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0449\u0435, \u0432 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043d\u0430\u0439\u0442\u0438 \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u0442\u0440\u0443\u0434\u0430, \u0435\u0441\u043b\u0438 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f.<\/p>\n<p>  \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438\/\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 Postman, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u0432\u043e\u0434\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u043e\u0442\u0432\u0435\u0442\u0430\u0445. \u042f \u0431\u0443\u0434\u0443 \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u0434\u0430, \u0435\u0441\u043b\u0438 \u043a\u043e\u043c\u0443-\u0442\u043e \u0443\u0440\u043e\u043a \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c! <\/p>\n<p>  \u0421\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e:<\/p>\n<p>  <b>1.<\/b> <a href=\"https:\/\/developers.google.com\/identity\/sign-in\/android\/start-integrating\">Google Sign-In for Android<\/a><br \/>  <b>2.<\/b> <a href=\"https:\/\/developers.google.com\/youtube\/2.0\/developers_guide_protocol_oauth2#OAuth2_Flows\">Youtube API. OAuth 2.0 flows<\/a><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\/325518\/\"> https:\/\/habrahabr.ru\/post\/325518\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<blockquote><p>\u00ab\u0421 20 \u0430\u043f\u0440\u0435\u043b\u044f 2017 \u0433\u043e\u0434\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u0438\u0437 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f\u00bb.<\/p><\/blockquote>\n<p> \u0422\u0430\u043a\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441 1 \u043c\u0430\u0440\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445, \u0433\u0434\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f. \u041e\u0431 \u044d\u0442\u043e\u043c Google \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0432 \u0441\u0432\u043e\u0451\u043c \u0431\u043b\u043e\u0433\u0435 \u0435\u0449\u0435 \u0432 \u0430\u0432\u0433\u0443\u0441\u0442\u0435 2016, \u0438 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0441\u043a\u043e\u0440\u043e \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438. \u041f\u0440\u0438\u044f\u0442\u043d\u043e\u0433\u043e \u043c\u0430\u043b\u043e, \u043e\u0434\u043d\u0430\u043a\u043e \u0432\u044b\u0445\u043e\u0434 \u0435\u0441\u0442\u044c \u2013 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u043c\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 Google Sign-in. <\/p>\n<p>  \u041e\u0431 \u044d\u0442\u043e\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u0435 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u0434\u0442\u0438 \u0440\u0435\u0447\u044c \u0432 \u0443\u0440\u043e\u043a\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u044b, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 API Google.   <\/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-284354","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284354","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=284354"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284354\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}