{"id":12136,"date":"2019-05-18T00:00:00","date_gmt":"2019-05-17T16:00:00","guid":{"rendered":"https:\/\/fgchen.com\/wpedu2\/2019\/05\/18\/google-drive-api-%e5%8f%96%e5%be%97%e6%aa%94%e6%a1%88%e7%9a%84meta%e8%b3%87%e6%96%99\/"},"modified":"2026-03-30T14:41:30","modified_gmt":"2026-03-30T06:41:30","slug":"google-drive-api-%e5%8f%96%e5%be%97%e6%aa%94%e6%a1%88%e7%9a%84meta%e8%b3%87%e6%96%99","status":"publish","type":"post","link":"https:\/\/fgchen.com\/wpedu\/2019\/05\/google-drive-api-%e5%8f%96%e5%be%97%e6%aa%94%e6%a1%88%e7%9a%84meta%e8%b3%87%e6%96%99\/","title":{"rendered":"Google Drive API &#8211; \u53d6\u5f97\u6a94\u6848\u7684meta\u8cc7\u6599"},"content":{"rendered":"\u6b65\u9a5f\uff1a\n\n<ol>\n    <li>\u81f3Google API Console\u7533\u8acbAPI\u91d1\u9300<\/li>\n    <li>\u555f\u7528Google Drive API<\/li>\n    <li>\u4f7f\u7528<a href=\"https:\/\/developers.google.com\/drive\/api\/v2\/reference\/files\/get\" target=\"_blank\" rel=\"noopener noreferrer\">Google Drive API Files: get<\/a>\u53d6\u5f97\u6a94\u6848meta\u8cc7\u6599\uff0c\u5e95\u4e0b\u7bc4\u4f8b\u7a0b\u5f0f\uff0c\u5370\u51fa\u6a94\u6848\u7684\u540d\u7a31\u3001\u63cf\u8ff0\u3001\u8207\u5efa\u7acb\u65e5\u671f\u3002<\/li>\n<\/ol>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n  &lt;meta charset=\"UTF-8\"&gt;\n  &lt;script src=\"https:\/\/apis.google.com\/js\/api.js\"&gt;&lt;\/script&gt; \/\/\u8f09\u5165google api js\u6a94\n  &lt;script&gt;\n    var FILE_ID = \"18GSM-p3BmsNMdhqr6NUFuYhPBpnHwGX0etM8V_s1X_Q\"; \/\/\u6a94\u6848ID\n    function printFile() {\n        var request = gapi.client.drive.files.get({\n            'fileId': FILE_ID\n        });\n        \/\/ \u4f7f\u7528gapi.client.drive.files.get\u65b9\u6cd5\uff0c\u6307\u5b9a'fileId': FILE_ID \u4f86\u53d6\u5f97\u6a94\u6848\u7684meta\u8cc7\u6599\uff0c\u65b9\u6cd5\u56de\u50b3\u64cd\u4f5c\u7269\u4ef6\uff0c\u547d\u540d\u70barequest\n        request.execute(function (resp) { \/\/\u57f7\u884crequest.execute\u65b9\u6cd5\uff0c\u4e26\u5c07\u65b9\u6cd5\u50b3\u56de\u4e4bresp\u7269\u4ef6\u70ba\u884c\u5167\u51fd\u5f0f\u53c3\u6578(function(resp))\uff0c\u57f7\u884c\u5e95\u4e0b\u6558\u8ff0\n          \/\/console.log\u662f\u9032\u5165Chrome\u958b\u767c\u6a21\u5f0f(\u6309F12)\u5f8c\uff0c\u8f38\u51fa\u8cc7\u6599\u81f3Console\uff0c\u85c9\u6b64\uff0c\u6211\u5011\u53ef\u89c0\u5bdf\u7a0b\u5f0f\u57f7\u884c\u904e\u7a0b\u4e2d\u7684\u8b8a\u6578\u3001\u7269\u4ef6\n          console.log('Title: ' + resp.title);\n          console.log('Description: ' + resp.description);\n          console.log('MIME type: ' + resp.mimeType);\n          \/\/ \u4e0b\u9762\u6558\u8ff0\u662f\u5178\u578bJS\u7f6e\u63dbHTML\u6587\u5b57\u7684\u7528\u6cd5\uff0c\u7528\u6cd5\u662f\u4f7f\u7528document.getElementById\u627e\u5230\u8981\u63db\u8cc7\u6599\u7684\u6a19\u7c64ID\uff0c\u518d\u7528innerHTML\u6307\u5b9a\u5167\u5bb9\uff0c\u8acb\u770b\u5e95\u4e0b&lt;p id='fileInfo'&gt;&lt;\/p&gt;\n          document.getElementById('fileInfo').innerHTML = \"\u6a94\u6848\u6a19\u984c\uff1a\"+resp.title+\"&lt;br&gt;\"+\n                                                          \"\u6a94\u6848\u63cf\u8ff0\uff1a\"+resp.description+\"&lt;br&gt;\"+\n                                                          \"\u6a94\u6848\u5efa\u7acb\u65e5\u671f\uff1a\"+resp.createdDate+\"&lt;br&gt;\";\n        });\n    }\n    function init() {\n      gapi.client.setApiKey('AIzaSyBQJVpHzi7hEMeQgCmZkkIYVjHkrRj1ClQ'); \/\/\u8a2d\u5b9a\u5f9eGoogle Developer Console\u53d6\u5f97\u7684API\u91d1\u9300\uff0c\u8a18\u5f97\u5fc5\u9808\u555f\u7528Google Drive API\n      gapi.client.load('drive', 'v2').then(printFile); \/\/\u547c\u53ebprintFile\uff0c\u5370\u51faFILE_ID\u6a94\u6848meta\u8cc7\u6599\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\n<ul>\n    <li>\u6a94\u6848\u8cc7\u6e90\u7684\u7269\u4ef6\u6b04\u4f4d\u8868\u793a\uff1a<a href=\"https:\/\/developers.google.com\/drive\/api\/v2\/reference\/files\" target=\"_blank\" rel=\"noopener noreferrer\">Google Drive Files Resource representations<\/a><\/li>\n<\/ul>\n\n<a href=\"https:\/\/fgchen.com\/wp\/google-drive-api-%e5%8f%96%e5%be%97%e6%aa%94%e6%a1%88%e7%9a%84meta%e8%b3%87%e6%96%99\/googleapikey\/\" rel=\"attachment wp-att-15556\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-large wp-image-15556\" src=\"https:\/\/fgchen.com\/wp\/wp-content\/uploads\/2019\/05\/GoogleAPIKey-1024x703.png\" alt=\"\" width=\"1024\" height=\"703\" \/><\/a>\n&nbsp;\n<a href=\"https:\/\/fgchen.com\/wp\/google-drive-api-%e5%8f%96%e5%be%97%e6%aa%94%e6%a1%88%e7%9a%84meta%e8%b3%87%e6%96%99\/googledriveapienable-1\/\" rel=\"attachment wp-att-15557\"><img decoding=\"async\" class=\"alignnone size-large wp-image-15557\" src=\"https:\/\/fgchen.com\/wp\/wp-content\/uploads\/2019\/05\/GoogleDriveAPIEnable-1-1024x407.png\" alt=\"\" width=\"1024\" height=\"407\" \/><\/a>\n&nbsp;\n<a href=\"https:\/\/fgchen.com\/wp\/google-drive-api-%e5%8f%96%e5%be%97%e6%aa%94%e6%a1%88%e7%9a%84meta%e8%b3%87%e6%96%99\/googledriveapienable-2\/\" rel=\"attachment wp-att-15558\"><img decoding=\"async\" class=\"alignnone size-full wp-image-15558\" src=\"https:\/\/fgchen.com\/wp\/wp-content\/uploads\/2019\/05\/GoogleDriveAPIEnable-2.png\" alt=\"\" width=\"835\" height=\"517\" \/><\/a>\n\u7d50\u679c\u5c55\u793a\uff1a\n<a href=\"https:\/\/fgchen.com\/wp\/google-drive-api-%e5%8f%96%e5%be%97%e6%aa%94%e6%a1%88%e7%9a%84meta%e8%b3%87%e6%96%99\/googledrivefiles\/\" rel=\"attachment wp-att-15552\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-15552\" src=\"https:\/\/fgchen.com\/wp\/wp-content\/uploads\/2019\/05\/GoogleDriveFiles-1024x583.png\" alt=\"\" width=\"1024\" height=\"583\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>\u6b65\u9a5f\uff1a \u81f3Google API Console\u7533\u8acbAPI\u91d1\u9300 \u555f\u7528Google  &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-12136","post","type-post","status-publish","format-standard","hentry","category-266"],"_links":{"self":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12136","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=12136"}],"version-history":[{"count":1,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12136\/revisions"}],"predecessor-version":[{"id":13490,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12136\/revisions\/13490"}],"wp:attachment":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/media?parent=12136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/categories?post=12136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/tags?post=12136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}