توضّح هذه الصفحة كيفية إزالة تصنيف من ملف واحد في Google Drive.
لإزالة البيانات الوصفية لتصنيف الملف من ملف، استخدِم طريقة
files.modifyLabels
. يحتوي نص الطلب على مثال ModifyLabelsRequest
لتعديل مجموعة التصنيفات في ملف. قد يحتوي الطلب على عدة تعديلات يتم تطبيقها بشكل متزامن. وهذا يعني أنّه إذا كانت أي تعديلات غير صالحة، سيتعذّر إجراء التعديل بالكامل ولن يتم تطبيق أي من التغييرات (التي قد تكون مرتبطة).
يحتوي ModifyLabelsRequest
على مثيل من
LabelModification
وهو تعديل على تصنيف في ملف. قد يحتوي أيضًا على مثيل
FieldModification
وهو تعديل على حقل تصنيف. لإزالة التصنيف من الملف،
اضبط قيمة FieldModification.removeLabel
على True
.
في حال نجاح الطلب، يحتوي نص الاستجابة على التصنيفات التي تمت إضافتها أو تعديلها. تتوفّر هذه السمة ضمن الكائن modifiedLabels
من النوع Label
.
مثال
يوضّح نموذج الرمز البرمجي التالي كيفية استخدام labelId
لإزالة جميع الحقول المرتبطة بالتسمية باستخدام fileId
. على سبيل المثال، إذا كان التصنيف يحتوي على حقلَي نص ومستخدم، سيؤدي حذف التصنيف إلى حذف كلٍّ من حقلَي النص والمستخدم المرتبطَين بالتصنيف. في المقابل، يؤدي إلغاء ضبط حقل النص إلى إزالته من التصنيف مع ترك حقل المستخدم بدون تغيير. لمزيد من المعلومات، يُرجى الاطّلاع على إزالة قيمة حقل تصنيف من ملف.
Java
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',
resource: labelModificationRequest,
});
return updateResponse;
} catch (err) {
// TODO (developer) - Handle error
throw err;
}
غيِّر القيم في السلسلة على الشكل التالي:
- LABEL_ID:
labelId
التصنيف المطلوب تعديله للعثور على التصنيفات في ملف، استخدِم الطريقةfiles.listLabels
. - FILE_ID:
fileId
الملف الذي تم تعديل التصنيفات الخاصة به.