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

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