
{"id":402,"date":"2026-12-06T10:01:05","date_gmt":"2026-12-06T03:01:05","guid":{"rendered":"https:\/\/uynghi.com\/?p=402"},"modified":"2026-12-06T10:04:09","modified_gmt":"2026-12-06T03:04:09","slug":"huong-dan-tao-client-id-va-client-secret-cua-google-drive-api-dung-cho-upload-file","status":"publish","type":"post","link":"https:\/\/uynghi.com\/huong-dan-tao-client-id-va-client-secret-cua-google-drive-api-dung-cho-upload-file\/","title":{"rendered":"H\u01b0\u1edbng d\u1eabn t\u1ea1o Client ID v\u00e0 Client secret c\u1ee7a Google Drive API d\u00f9ng cho upload file"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u0110\u1ec3 upload file l\u00ean Google Drive b\u1eb1ng OAuth 2.0 v\u00e0 duy tr\u00ec k\u1ebft n\u1ed1i l\u00e2u d\u00e0i qua <code class=\"\">GOOGLE REFRESH TOKEN<\/code>, b\u1ea1n c\u1ea7n c\u1ea5u h\u00ecnh d\u1ef1 \u00e1n tr\u00ean <strong>Google Cloud Console<\/strong>, l\u1ea5y l\u1ea7n \u0111\u1ea7u <code class=\"\">GOOGLE_REFRESH_TOKEN<\/code> (v\u1edbi <code class=\"\">access_type=offline<\/code>), sau \u0111\u00f3 d\u00f9ng token n\u00e0y \u0111\u1ec3 t\u1ef1 \u0111\u1ed9ng l\u00e0m m\u1edbi <code class=\"\">access_token<\/code> khi g\u1ecdi API.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Ph\u1ea7n 1: T\u1ea1o GOOGLE_CLIENT_ID v\u00e0 GOOGLE_CLIENT_SECRET<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>T\u1ea1o Project tr\u00ean Google Cloud Console<\/strong>:<\/p>\n\n\n\n<ul id=\"p-rc_aab54ced5649be05-40\" class=\"wp-block-list\">\n<li>Truy c\u1eadp <a href=\"https:\/\/console.cloud.google.com\/\" target=\"_blank\" rel=\"noopener\">Google Cloud Console<\/a> v\u00e0 t\u1ea1o m\u1ed9t Project m\u1edbi (v\u00ed d\u1ee5: <code class=\"\">drive-uploader<\/code>).<\/li>\n\n\n\n<li>Ch\u1ecdn \u0111\u00fang Project v\u1eeba t\u1ea1o \u1edf thanh tr\u00ean c\u00f9ng.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>B\u1eadt Google Drive API<\/strong>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">V\u00e0o <strong>APIs &amp; Services<\/strong> \u2192 <strong>Library<\/strong>, t\u00ecm <strong>Google Drive API<\/strong> v\u00e0 b\u1ea5m <strong>Enable<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"812\" src=\"https:\/\/uynghi.com\/asset\/uploads\/2026\/12\/post-huong-dan-tao-client-id-va-client-secret-cua-google-drive-api-dung-cho-upload-file-1796526236-1024x812.jpg\" alt=\"\" class=\"wp-image-407\" srcset=\"https:\/\/uynghi.com\/asset\/uploads\/2026\/12\/post-huong-dan-tao-client-id-va-client-secret-cua-google-drive-api-dung-cho-upload-file-1796526236-1024x812.jpg 1024w, https:\/\/uynghi.com\/asset\/uploads\/2026\/12\/post-huong-dan-tao-client-id-va-client-secret-cua-google-drive-api-dung-cho-upload-file-1796526236-300x238.jpg 300w, https:\/\/uynghi.com\/asset\/uploads\/2026\/12\/post-huong-dan-tao-client-id-va-client-secret-cua-google-drive-api-dung-cho-upload-file-1796526236-768x609.jpg 768w, https:\/\/uynghi.com\/asset\/uploads\/2026\/12\/post-huong-dan-tao-client-id-va-client-secret-cua-google-drive-api-dung-cho-upload-file-1796526236-1536x1218.jpg 1536w, https:\/\/uynghi.com\/asset\/uploads\/2026\/12\/post-huong-dan-tao-client-id-va-client-secret-cua-google-drive-api-dung-cho-upload-file-1796526236.jpg 1700w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>C\u1ea5u h\u00ecnh OAuth Consent Screen<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>V\u00e0o <strong>APIs &amp; Services<\/strong> \u2192 <strong>OAuth consent screen<\/strong> (ho\u1eb7c <strong>Google Auth Platform<\/strong>).<\/li>\n\n\n\n<li>Ch\u1ecdn <strong>External<\/strong> (n\u1ebfu d\u00f9ng t\u00e0i kho\u1ea3n Gmail c\u00e1 nh\u00e2n).<\/li>\n\n\n\n<li>\u0110i\u1ec1n App name, email h\u1ed7 tr\u1ee3 v\u00e0 email nh\u00e0 ph\u00e1t tri\u1ec3n.<\/li>\n\n\n\n<li>\u1ede m\u1ee5c <strong>Scopes<\/strong>, th\u00eam scope <code>[https:\/\/www.googleapis.com\/auth\/drive.file](https:\/\/www.googleapis.com\/auth\/drive.file)<\/code> (ch\u1ec9 thao t\u00e1c v\u1edbi file do app t\u1ea1o ho\u1eb7c ng\u01b0\u1eddi d\u00f9ng ch\u1ecdn qua Picker; tr\u00e1nh d\u00f9ng scope r\u1ed9ng n\u1ebfu kh\u00f4ng c\u1ea7n thi\u1ebft).<\/li>\n\n\n\n<li>\u1ede m\u1ee5c <strong>Test users<\/strong>, th\u00eam ch\u00ednh \u0111\u1ecba ch\u1ec9 Gmail c\u1ee7a b\u1ea1n \u0111\u1ec3 c\u1ea5p quy\u1ec1n khi app c\u00f2n \u1edf tr\u1ea1ng th\u00e1i <strong>Testing<\/strong>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>T\u1ea1o OAuth Client ID &amp; Secret<\/strong>:<\/p>\n\n\n\n<ul id=\"p-rc_aab54ced5649be05-46\" class=\"wp-block-list\">\n<li>V\u00e0o <strong>Credentials<\/strong> \u2192 <strong>Create credentials<\/strong> \u2192 <strong>OAuth client ID<\/strong>.<\/li>\n\n\n\n<li>Ch\u1ecdn <strong>Desktop app<\/strong> (n\u1ebfu ch\u1ea1y script\/CLI\/backend c\u1ee5c b\u1ed9) ho\u1eb7c <strong>Web application<\/strong> (n\u1ebfu c\u00f3 callback URL tr\u00ean web\/server).<\/li>\n\n\n\n<li>L\u01b0u l\u1ea1i <strong>Client ID<\/strong> (<code class=\"\">GOOGLE_CLIENT_ID<\/code>) v\u00e0 <strong>Client Secret<\/strong> (<code class=\"\">GOOGLE_CLIENT_SECRET<\/code>).<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Ph\u1ea7n 2: L\u1ea5y <code>GOOGLE_REFRESH_TOKEN<\/code> l\u1ea7n \u0111\u1ea7u<\/h2>\n","protected":false},"excerpt":{"rendered":"<p>\u0110\u1ec3 upload file l\u00ean Google Drive b\u1eb1ng OAuth 2.0 v\u00e0 duy tr\u00ec k\u1ebft n\u1ed1i l\u00e2u d\u00e0i qua GOOGLE REFRESH TOKEN, [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":406,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-402","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-huong-dan"],"views":10,"_links":{"self":[{"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/posts\/402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/comments?post=402"}],"version-history":[{"count":5,"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/posts\/402\/revisions"}],"predecessor-version":[{"id":409,"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/posts\/402\/revisions\/409"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/media\/406"}],"wp:attachment":[{"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/media?parent=402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/categories?post=402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/tags?post=402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}