{"id":12137,"date":"2019-05-24T00:00:00","date_gmt":"2019-05-23T16:00:00","guid":{"rendered":"https:\/\/fgchen.com\/wpedu2\/2019\/05\/24\/google-drive-api-%e5%88%97%e5%87%ba%e8%b3%87%e6%96%99%e5%a4%be%e6%89%80%e6%9c%89%e7%9a%84%e6%aa%94%e6%a1%88\/"},"modified":"2026-03-30T14:41:28","modified_gmt":"2026-03-30T06:41:28","slug":"google-drive-api-%e5%88%97%e5%87%ba%e8%b3%87%e6%96%99%e5%a4%be%e6%89%80%e6%9c%89%e7%9a%84%e6%aa%94%e6%a1%88","status":"publish","type":"post","link":"https:\/\/fgchen.com\/wpedu\/2019\/05\/google-drive-api-%e5%88%97%e5%87%ba%e8%b3%87%e6%96%99%e5%a4%be%e6%89%80%e6%9c%89%e7%9a%84%e6%aa%94%e6%a1%88\/","title":{"rendered":"Google Drive API &#8211; \u5217\u51fa\u8cc7\u6599\u593e\u6240\u6709\u7684\u6a94\u6848"},"content":{"rendered":"\u6b64\u7bc7\u6587\u7ae0\u4f7f\u7528<a href=\"https:\/\/developers.google.com\/drive\/api\/v3\/search-files\" target=\"_blank\" rel=\"noopener noreferrer\">Google Drive API files:list q\u53c3\u6578\u65b9\u6cd5<\/a> \u4f86\u8d70\u8a2a\u8cc7\u6599\u593e\u88cf\u7684\u6240\u6709\u6a94\u6848(\u542b\u8cc7\u6599\u593e)<strong>\uff1a<\/strong>\n<a href=\"https:\/\/fgchen.com\/wp\/google-drive-api-%e5%88%97%e5%87%ba%e8%b3%87%e6%96%99%e5%a4%be%e6%89%80%e6%9c%89%e7%9a%84%e6%aa%94%e6%a1%88\/q-in-parents\/\" rel=\"attachment wp-att-15572\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-15572\" src=\"https:\/\/fgchen.com\/wp\/wp-content\/uploads\/2019\/05\/q-in-parents.png\" alt=\"\" width=\"876\" height=\"122\" \/><\/a>\n\u5217\u51fa\u67d0\u500b\u8cc7\u6599\u593e\u6240\u6709\u7684\u6a94\u6848\uff1a\nhttps:\/\/a02.fgchen.com\/myWebApp\/GoogleDrive\/i5.html\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">&lt;!DOCTYPE html&gt;\n&lt;head&gt;\n    &lt;meta charset=\"UTF-8\"&gt;\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n    &lt;meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\"&gt;\n    &lt;script src=\"https:\/\/apis.google.com\/js\/api.js\"&gt;&lt;\/script&gt;\n    &lt;script&gt;\n      var FOLDER_ID = \"1QjSA-EBfbAIBoe2UKvkJbBKzkInDLNFu\"; \/\/Google\u8cc7\u6599\u593eID\n      function printFile(fileId) {\n        var request = gapi.client.drive.files.list({\n              'q' : \"'\" + FOLDER_ID + \"' in parents\"\n        });\n        \/\/\u4f7f\u7528gapi.client.drive.files.list\u7684'q'\u53c3\u6578\u9032\u884c\u8cc7\u6599\u593eid\u7684\u5217\u8868\uff0c\u6b64\u65b9\u6cd5\u6703\u56de\u50b3\u8cc7\u6599\u593e\u4e2d\u6240\u6709\u7684\u6a94\u6848(\u5305\u542b\u8cc7\u6599\u593e)\uff0cresp.items\u70ba\u9019\u4e9b\u6a94\u6848\u7684\u96c6\u5408\u7269\u4ef6\u3002\n        request.execute(function (resp) {\n          if(resp &amp;&amp; resp.items.length &gt; 0) { \/\/\u5982\u679cresp\u7269\u4ef6\u4e0d\u662f\u7a7a\u7684\u8a71 \u800c\u4e14 resp.items\u9805\u76ee\u5143\u7d20\u5927\u65bc0\u7684\u8a71\n            for (var i=0; i &lt; resp.items.length; i++){ \/\/\u8d70\u8a2aitems\u9019\u500b\u96c6\u5408\u7269\u4ef6\n            var f = resp.items[i]; \/\/\u4f7f\u7528f\u6307\u5411items\u6307\u5b9a\u7684\u6bcf\u4e00\u500b\u6a94\u6848\u7269\u4ef6\n            \/\/ console.log('Title: ' + f.title);\n            \/\/ console.log('Description: ' + f.description);\n            \/\/ console.log('MIME type: ' + f.mimeType);\n            document.getElementById('fileInfo').innerHTML +=\n                                                             \"\u6a94\u6848\u6a19\u984c\uff1a\"+f.title+\"&lt;br&gt;\" +\n                                                             \"\u6a94\u6848\u63cf\u8ff0\uff1a\"+f.description+\"&lt;br&gt;\" +\n                                                             \"\u6a94\u6848\u5efa\u7acb\u65e5\u671f\uff1a\"+f.createdDate+\"&lt;br&gt;\" +\n                                                             \"\u6a94\u6848\u4fee\u6539\u65e5\u671f\uff1a\"+f.modifiedDate+\"&lt;br&gt;\" +\n                                                             \"\u6a94\u6848\u578b\u614b\uff1a\"+f.mimeType+\"&lt;br&gt;\" +\n                                                             \"\u6a94\u6848\u64c1\u6709\u8005\uff1a\"+f.ownerNames +\"&lt;br&gt;&lt;hr&gt;\";\n          }\n        }\n        });\n      }\n      function init() {\n          gapi.client.setApiKey('AIzaSyBQJVpHzi7hEMeQgCmZkkIYVjHkrRj1ClQ'); \/\/\u4f60\u7684API\u91d1\u9300\n          gapi.client.load('drive', 'v2').then(printFile);\n      }\n      gapi.load('client', init);\n    &lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n  &lt;p id='fileInfo'&gt;&lt;\/p&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n\n&nbsp;\n\u57f7\u884c\u7d50\u679c\uff1a\n<a href=\"https:\/\/fgchen.com\/wp\/google-drive-api-%e5%88%97%e5%87%ba%e8%b3%87%e6%96%99%e5%a4%be%e6%89%80%e6%9c%89%e7%9a%84%e6%aa%94%e6%a1%88\/googleapi-i5\/\" rel=\"attachment wp-att-15579\"><img decoding=\"async\" class=\"alignnone size-full wp-image-15579\" src=\"https:\/\/fgchen.com\/wp\/wp-content\/uploads\/2019\/05\/GoogleAPI-i5.png\" alt=\"\" width=\"724\" height=\"625\" \/><\/a>\n&nbsp;\n\u627e\u7279\u5b9a\u8cc7\u6599\u593e\u88cf\u7684\u6a94\u6848\uff1a\nhttps:\/\/a02.fgchen.com\/myWebApp\/GoogleDrive\/i7.html?q=a1\n\u9019\u500b\u7bc4\u4f8b\u4e5f\u793a\u7bc4\u4e86\u5982\u4f55\u5f9eurl\u53d6\u51fa\u53c3\u6578a1\u3002(window.location.search.substring(1);)\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">&lt;!DOCTYPE html&gt;\n&lt;head&gt;\n    &lt;meta charset=\"UTF-8\"&gt;\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n    &lt;meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\"&gt;\n    &lt;script src=\"https:\/\/apis.google.com\/js\/api.js\"&gt;&lt;\/script&gt;\n    &lt;script&gt;\n      var FOLDER_ID = \"1QjSA-EBfbAIBoe2UKvkJbBKzkInDLNFu\"; \/\/Google\u8cc7\u6599\u593eID\n      function printFile(fileId) {\n        var request = gapi.client.drive.files.list({\n              'q' : \"'\" + FOLDER_ID + \"' in parents\"\n        });\n        \/\/\u4f7f\u7528gapi.client.drive.files.list\u7684'q'\u53c3\u6578\u9032\u884c\u8cc7\u6599\u593eid\u7684\u5217\u8868\uff0c\u6b64\u65b9\u6cd5\u6703\u56de\u50b3\u8cc7\u6599\u593e\u4e2d\u6240\u6709\u7684\u6a94\u6848(\u5305\u542b\u8cc7\u6599\u593e)\uff0cresp.items\u70ba\u9019\u4e9b\u6a94\u6848\u7684\u96c6\u5408\u7269\u4ef6\u3002\n        request.execute(function (resp) {\n          if(resp &amp;&amp; resp.items.length &gt; 0) { \/\/\u5982\u679cresp\u7269\u4ef6\u4e0d\u662f\u7a7a\u7684\u8a71 \u800c\u4e14 resp.items\u9805\u76ee\u5143\u7d20\u5927\u65bc0\u7684\u8a71\n            for (var i=0; i &lt; resp.items.length; i++){ \/\/\u8d70\u8a2aitems\u9019\u500b\u96c6\u5408\u7269\u4ef6\n            var f = resp.items[i]; \/\/\u4f7f\u7528f\u6307\u5411items\u6307\u5b9a\u7684\u6bcf\u4e00\u500b\u6a94\u6848\u7269\u4ef6\n            \/\/ console.log('Title: ' + f.title);\n            \/\/ console.log('Description: ' + f.description);\n            \/\/ console.log('MIME type: ' + f.mimeType);\n            if (f.title == qs) { \/\/\u5982\u679cf\u6a94\u6848\u7684\u6a19\u984c\u7b49\u65bcqs\u6240\u8981\u67e5\u8a62\u7684\u95dc\u9375\u5b57\u2026\n              \/\/ console.log(f);\n            \/\/   var pathname =  gapi.client.drive.files.get({'fileID' : f.parents[0].id});\n            \/\/   var pn;\n            \/\/   pathname.execute(function(rp) {\n            \/\/     pn = rp.title;\n            \/\/   });\n              document.getElementById('fileInfo').innerHTML += \"\u6240\u8981\u627e\u7684\u6a94\u6848\uff1a&lt;br&gt;\" +\n                                                               f.title+\"&lt;br&gt;\" +\n                                                               f.description+\"&lt;br&gt;\" +\n                                                               f.createdDate+\"&lt;br&gt;\" +\n                                                               f.modifiedDate+\"&lt;br&gt;\" +\n                                                               f.ownerNames +\"&lt;br&gt;\";\n            }\n          }\n        }\n        });\n      }\n      function init() {\n          gapi.client.setApiKey('AIzaSyBQJVpHzi7hEMeQgCmZkkIYVjHkrRj1ClQ'); \/\/\u4f60\u7684API\u91d1\u9300\n          gapi.client.load('drive', 'v2').then(printFile);\n      }\n      var q = window.location.search.substring(1); \/\/\u53d6\u5f97url\u5b57\u4e32\"?\"\u5f8c\u4e4b\u5b57\u4e32\uff0c\u4f8b\uff1a?q=a1\uff0cq\u70ba\"a1\"\n      var qs = q.split(\"=\")[1]; \/\/\u5c07q\u5b57\u4e32\u4ee5\"=\"\u505a\u70ba\u5206\u5272\u5b57\u5143\uff0c\u5206\u62102\u500b\u5b57\u4e32\uff0c\u5176\u4e2d\"=\"\u5f8c\u9762\u7684\u5b57\u4e32\"a1\"\u4fc2\u50b3\u56de\u7684\u9663\u5217\u4e2d\u7684\u7b2c[1]\u500b\u5143\u7d20\uff0cqs=\"a1\"\u3002\n      \/\/ console.log(qs);\n      gapi.load('client', init);\n    &lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n  &lt;p id='fileInfo'&gt;&lt;\/p&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n\n&nbsp;","protected":false},"excerpt":{"rendered":"<p>\u6b64\u7bc7\u6587\u7ae0\u4f7f\u7528Google Drive API files:list q\u53c3\u6578\u65b9\u6cd5  &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","fifu_image_url":"","fifu_image_alt":"","footnotes":""},"categories":[266],"tags":[],"class_list":["post-12137","post","type-post","status-publish","format-standard","hentry","category-266"],"_links":{"self":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/comments?post=12137"}],"version-history":[{"count":1,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12137\/revisions"}],"predecessor-version":[{"id":13655,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12137\/revisions\/13655"}],"wp:attachment":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/media?parent=12137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/categories?post=12137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/tags?post=12137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}