إزالة تصنيف من ملف

توضّح هذه الصفحة كيفية إزالة تصنيف من ملف واحد في 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 للملف الذي تم تعديل التصنيفات له