توضِّح هذه الصفحة كيفية إزالة تصنيف من ملف واحد في Google Drive.
لإزالة بيانات التصنيف الوصفية للملف، استخدِم طريقة
files.modifyLabels. يحتوي
نص الطلب
على مثال
ModifyLabelsRequest
لتعديل مجموعة التصنيفات في ملف. قد يحتوي الطلب على عدة تعديلات يتم تطبيقها بشكل متكامل. أي إذا كانت أي تعديلات غير صالحة، لن ينجح التعديل بالكامل ولن يتم تطبيق أي من التغييرات (التي قد تكون مرتبطة).
يحتوي ModifyLabelsRequest على مثال
LabelModification
وهو تعديل لتصنيف في ملف. قد يحتوي أيضًا على مثال
من
FieldModification
وهو تعديل لحقل تصنيف. لإزالة التصنيف من الملف، اضبط FieldModification.removeLabel على True.
إذا كانت الاستجابة ناجحة، يحتوي نص
الاستجابة على
التصنيفات التي تمت إضافتها أو تعديلها من خلال الطلب. تظهر هذه التصنيفات ضمن عنصر
modifiedLabels من النوع Label.
مثال
توضح عينة التعليمات البرمجية التالية كيفية استخدام labelId لإزالة جميع الحقول المرتبطة بالتصنيف باستخدام fileId. على سبيل المثال، إذا كان التصنيف يحتوي على
حقلَي نص ومستخدم، يؤدي إزالة التصنيف إلى حذف كل من حقلَي النص والمستخدم
المرتبطَين بالتصنيف. في المقابل، يؤدي إلغاء ضبط حقل النص إلى إزالته
من التصنيف ولكن يبقى حقل المستخدم بدون تغيير. لمزيد من المعلومات، يُرجى الاطِّلاع على
إلغاء ضبط حقل تصنيف في ملف.
جافا
ModifyLabelsRequest modifyLabelsRequest = new ModifyLabelsRequest()
.setLabelModifications(ImmutableList.of(
new LabelModification()
.setLabelId("LABEL_ID")
.setRemoveLabel(true)));
ModifyLabelsResponse modifyLabelsResponse = driveService.files()
.modifyLabels("FILE_ID", modifyLabelsRequest)
.execute();
Python
label_modification = {
'labelId': 'LABEL_ID',
'removeLabel': True
}
modified_labels = drive_service.files().modifyLabels(
fileId="FILE_ID",
body={'labelModifications': [label_modification]}
).execute()
Node.js
/**
* Remove a label on a Drive file
* @return{obj} updated label data
**/
async function removeLabel() {
// Get credentials and build service
// TODO (developer) - Use appropriate auth mechanism for your app
const {GoogleAuth} = require('google-auth-library');
const {google} = require('googleapis');
const auth = new GoogleAuth({
scopes: 'https://www.googleapis.com/auth/drive',
});
const service = google.drive({version: 'v3', auth});
const labelModification = {
'labelId': 'LABEL_ID',
'removeLabel': true,
};
const labelModificationRequest = {
'labelModifications': [labelModification],
};
try {
const updateResponse = await service.files.modifyLabels({
fileId: 'FILE_ID',
requestBody: labelModificationRequest,
});
return updateResponse;
} catch (err) {
// TODO (developer) - Handle error
throw err;
}
}
غيِّر القيم في السلسلة على الشكل التالي:
- LABEL_ID:
labelIdللتصنيف الذي تريد تعديله. للعثور على التصنيفات في ملف، استخدِمfiles.listLabelsطريقة. - FILE_ID:
fileIdللملف الذي تم تعديل تصنيفاته.