Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
Создавайте и управляйте метками для файлов и папок на Диске с помощью расширенного сервиса Google Drive Labels. С помощью этого расширенного сервиса вы можете использовать все функции API Drive Labels в Apps Script.
Подробнее об этом сервисе см. в документации по API Google Drive Labels . Как и все расширенные сервисы в Apps Script, API Drive Labels использует те же объекты, методы и параметры, что и общедоступный API.
Чтобы сообщить о проблемах и получить другую поддержку, см. руководство по поддержке API меток 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);}
Получить этикетку
В следующем примере кода показано, как получить отдельную метку по имени её ресурса (строковому значению метки). Чтобы узнать имя метки, получите список меток через API или воспользуйтесь менеджером меток Диска. Подробнее о менеджере меток см. в разделе Управление метками Диска .
/** * 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);}}
Список меток для элемента Диска
В следующем примере кода показано, как получить элемент Диска и вывести список всех меток, примененных к этому элементу.
/** * 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);}}
[[["Прост для понимания","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"]],["Последнее обновление: 2025-07-24 UTC."],[[["Utilize 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."],["To use this advanced service, ensure you enable the Advanced Drive Service in your Apps Script project settings before implementation."],["Access comprehensive documentation and support resources for the Google Drive Labels API, which uses the same structure as the public API, in the provided references."],["Explore 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."]]],[]]