קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
שירות Drive המתקדם מאפשר להשתמש ב-Google Drive API ב-Apps Script. בדומה לשירות Drive המובנה של Apps Script, ממשק ה-API הזה מאפשר ל-scripts ליצור, למצוא ולשנות קבצים ותיקיות ב-Google Drive. ברוב המקרים קל יותר להשתמש בשירות המובנה, אבל השירות המתקדם הזה מספק כמה תכונות נוספות, כולל גישה למאפייני קבצים מותאמים אישית וגרסאות של קבצים ותיקיות.
חומרי עזר
מידע מפורט על השירות הזה זמין במסמכי העזרה של Google Drive API. כמו כל השירותים המתקדמים ב-Apps Script, גם בשירות המתקדם של Drive נעשה שימוש באותם אובייקטים, שיטות ופרמטרים כמו ב-API הציבורי. מידע נוסף זמין במאמר איך נקבעות חתימות של שיטות.
/** * 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);}}
הצגת רשימה של תיקיות
בדוגמת הקוד הבאה מוסבר איך להציג את רשימת התיקיות ברמה העליונה ב-Drive של המשתמש. שימו לב לשימוש באסימוני דפים כדי לגשת לרשימת התוצאות המלאה.
/** * 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);}
הוספת מאפייני קובץ
בדוגמת הקוד הבאה נעשה שימוש בשדה appProperties כדי להוסיף מאפיין מותאם אישית לקובץ. הנכס המותאם אישית גלוי רק לסקריפט. כדי להוסיף למאפיין properties, צריך להשתמש בשדה properties במקום בשדה properties. מידע נוסף זמין במאמר הוספת מאפייני קבצים בהתאמה אישית.
/** * 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."]]],[]]