บริการไดรฟ์ขั้นสูงช่วยให้คุณใช้ Google Drive API ใน Apps Script ได้ API นี้ช่วยให้สคริปต์สร้าง ค้นหา และแก้ไขไฟล์และโฟลเดอร์ใน Google ไดรฟ์ได้ เช่นเดียวกับบริการไดรฟ์ในตัวของ Apps Script ในกรณีส่วนใหญ่ บริการในตัวจะใช้งานได้ง่ายกว่า แต่บริการขั้นสูงนี้มีฟีเจอร์เพิ่มเติมบางอย่าง เช่น การเข้าถึงพร็อพเพอร์ตี้ไฟล์ที่กำหนดเอง รวมถึงการแก้ไขไฟล์และโฟลเดอร์
ข้อมูลอ้างอิง
ดูข้อมูลโดยละเอียดเกี่ยวกับบริการนี้ได้ในเอกสารอ้างอิงของ Google Drive API บริการไดรฟ์ขั้นสูงใช้ออบเจ็กต์ วิธีการ และพารามิเตอร์เดียวกันกับ API สาธารณะเช่นเดียวกับบริการขั้นสูงทั้งหมดใน Apps Script ดูข้อมูลเพิ่มเติมได้ที่วิธีกำหนดลายเซ็นเมธอด
/** * Uploads a new file to the user's Drive. */functionuploadFile(){try{// Makes a request to fetch a URL.constimage=UrlFetchApp.fetch('http://goo.gl/nd7zjB').getBlob();letfile={name:'google_logo.png',mimeType:'image/png'};// Create a file in the user's Drive.file=Drive.Files.create(file,image,{'fields':'id,size'});console.log('ID:%s,Filesize(bytes):%s',file.id,file.size);}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failedtouploadfilewitherror%s',err.message);}}
/** * Lists the top-level folders in the user's Drive. */functionlistRootFolders(){constquery='"root"inparentsandtrashed=falseand'+'mimeType="application/vnd.google-apps.folder"';letfolders;letpageToken=null;do{try{folders=Drive.Files.list({q:query,pageSize:100,pageToken:pageToken});if(!folders.files||folders.files.length===0){console.log('Allfoldersfound.');return;}for(leti=0;i < folders.files.length;i++){constfolder=folders.files[i];console.log('%s(ID:%s)',folder.name,folder.id);}pageToken=folders.nextPageToken;}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failedwitherror%s',err.message);}}while(pageToken);}
/** * Lists the revisions of a given file. * @param {string} fileId The ID of the file to list revisions for. */functionlistRevisions(fileId){letrevisions;constpageToken=null;do{try{revisions=Drive.Revisions.list(fileId,{'fields':'revisions(modifiedTime,size),nextPageToken'});if(!revisions.revisions||revisions.revisions.length===0){console.log('Allrevisionsfound.');return;}for(leti=0;i < revisions.revisions.length;i++){constrevision=revisions.revisions[i];constdate=newDate(revision.modifiedTime);console.log('Date:%s,Filesize(bytes):%s',date.toLocaleString(),revision.size);}pageToken=revisions.nextPageToken;}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failedwitherror%s',err.message);}}while(pageToken);}
/** * Adds a custom app property to a file. Unlike Apps Script's DocumentProperties, * Drive's custom file properties can be accessed outside of Apps Script and * by other applications; however, appProperties are only visible to the script. * @param {string} fileId The ID of the file to add the app property to. */functionaddAppProperty(fileId){try{letfile={'appProperties':{'department':'Sales'}};// Updates a file to add an app property.file=Drive.Files.update(file,fileId,null,{'fields':'id,appProperties'});console.log('ID:%s,appProperties:%s',file.id,JSON.stringify(file.appProperties,null,2));}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failedwitherror%s',err.message);}}
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2024-12-21 UTC"],[[["The advanced Drive service in Apps Script provides more features than the built-in service, like access to custom file properties and revisions."],["This advanced service requires enabling before use and mirrors the functionality of the Google Drive API."],["Code samples demonstrate how to upload files, list folders and revisions, and add custom properties to files in Google Drive using this service."],["The provided samples utilize version 3 of the Google Drive API and illustrate common Drive operations within Apps Script."],["For comprehensive details, refer to the Google Drive API reference documentation and support guide."]]],[]]