Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Tạo và quản lý nhãn cho tệp và thư mục trên Drive bằng dịch vụ nâng cao Nhãn của Google Drive. Với dịch vụ nâng cao này, bạn có thể sử dụng tất cả các tính năng của Drive Labels API trong Apps Script.
Để biết thêm thông tin về dịch vụ này, hãy xem tài liệu về Google Drive Labels API. Giống như tất cả các dịch vụ nâng cao trong Apps Script, dịch vụ Drive Labels API sử dụng cùng các đối tượng, phương thức và tham số như API công khai.
Để báo cáo vấn đề và tìm thông tin hỗ trợ khác, hãy xem hướng dẫn hỗ trợ về API Nhãn của Google Drive.
/** * List labels available to the user. */functionlistLabels(){letpageToken=null;letlabels=[];do{try{constresponse=DriveLabels.Labels.list({publishedOnly:true,pageToken:pageToken});pageToken=response.nextPageToken;labels=labels.concat(response.labels);}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failed to list labels with error %s',err.message);}}while(pageToken!=null);console.log('Found %d labels',labels.length);}
Nhận nhãn
Mẫu mã sau đây cho thấy cách lấy một nhãn duy nhất theo tên tài nguyên (là giá trị chuỗi của nhãn). Để tìm tên nhãn, hãy lấy danh sách nhãn thông qua API hoặc sử dụng trình quản lý nhãn của Drive. Để biết thêm thông tin về trình quản lý nhãn, hãy xem bài viết Quản lý nhãn trong Drive.
/** * Get a label by name. * @param {string} labelName The label name. */functiongetLabel(labelName){try{constlabel=DriveLabels.Labels.get(labelName,{view:'LABEL_VIEW_FULL'});consttitle=label.properties.title;constfieldsLength=label.fields.length;console.log(`Fetched label with title: '${title}' and ${fieldsLength} fields.`);}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failed to get label with error %s',err.message);}}
Liệt kê nhãn cho một mục trên Drive
Mã mẫu sau đây cho biết cách lấy một mục trên Drive và liệt kê tất cả nhãn được áp dụng cho mục đó.
/** * List Labels on a Drive Item * Fetches a Drive Item and prints all applied values along with their to their * human-readable names. * * @param {string} fileId The Drive File ID */functionlistLabelsOnDriveItem(fileId){try{constappliedLabels=Drive.Files.listLabels(fileId);console.log('%d label(s) are applied to this file',appliedLabels.labels.length);appliedLabels.labels.forEach((appliedLabel)=>{// Resource name of the label at the applied revision.constlabelName='labels/'+appliedLabel.id+'@'+appliedLabel.revisionId;console.log('Fetching Label: %s',labelName);constlabel=DriveLabels.Labels.get(labelName,{view:'LABEL_VIEW_FULL'});console.log('Label Title: %s',label.properties.title);Object.keys(appliedLabel.fields).forEach((fieldId)=>{constfieldValue=appliedLabel.fields[fieldId];constfield=label.fields.find((f)=>f.id==fieldId);console.log(`Field ID: ${field.id}, Display Name: ${field.properties.displayName}`);switch(fieldValue.valueType){case'text':console.log('Text: %s',fieldValue.text[0]);break;case'integer':console.log('Integer: %d',fieldValue.integer[0]);break;case'dateString':console.log('Date: %s',fieldValue.dateString[0]);break;case'user':constuser=fieldValue.user.map((user)=>{return`${user.emailAddress}: ${user.displayName}`;}).join(', ');console.log(`User: ${user}`);break;case'selection':constchoices=fieldValue.selection.map((choiceId)=>{returnfield.selectionOptions.choices.find((choice)=>choice.id===choiceId);});constselection=choices.map((choice)=>{return`${choice.id}: ${choice.properties.displayName}`;}).join(', ');console.log(`Selection: ${selection}`);break;default:console.log('Unknown: %s',fieldValue.valueType);console.log(fieldValue.value);}});});}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failed with error %s',err.message);}}
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-31 UTC."],[[["\u003cp\u003eUtilize the Google Drive Labels advanced service in Apps Script to create and manage labels for your Google Drive files and folders, leveraging the Drive Labels API.\u003c/p\u003e\n"],["\u003cp\u003eTo use this advanced service, ensure you enable the Advanced Drive Service in your Apps Script project settings before implementation.\u003c/p\u003e\n"],["\u003cp\u003eAccess comprehensive documentation and support resources for the Google Drive Labels API, which uses the same structure as the public API, in the provided references.\u003c/p\u003e\n"],["\u003cp\u003eExplore the provided sample code snippets to learn how to list available labels, retrieve specific labels by name, and list labels applied to Drive items using Apps Script.\u003c/p\u003e\n"]]],[],null,[]]