किसी फ़ाइल पर लेबल फ़ील्ड को अनसेट करना

इस पेज पर, लेबल को अनसेट करने का तरीका बताया गया है Field सिंगल Google Drive फ़ाइल.

फ़ाइल लेबल अनसेट करके किसी फ़ाइल से मेटाडेटा हटाने के लिए, files.modifyLabels तरीका. कॉन्टेंट बनाने अनुरोध का मुख्य हिस्सा इसमें ModifyLabelsRequest . अनुरोध में कई चीज़ें शामिल हो सकती हैं जो अपने आप लागू होते हैं. इसका मतलब है कि अगर कोई बदलाव मान्य है, तो पूरा अपडेट असफल होता है और इनमें से कोई भी नहीं डिपेंडेंट) के हिसाब से बदलाव लागू होते हैं.

ModifyLabelsRequest में LabelModification जो किसी फ़ाइल पर मौजूद लेबल में किया गया बदलाव है. इसमें एक उदाहरण भी शामिल हो सकता है में से FieldModification जो किसी लेबल फ़ील्ड में बदलाव है. फ़ील्ड की वैल्यू को सेट नहीं करने के लिए, FieldModification.unsetValues को True पर सेट करें.

सफल होने पर, जवाब बॉडी में शामिल है जोड़े या अपडेट किए गए लेबल. ये डाइमेंशन Label टाइप का modifiedLabels ऑब्जेक्ट.

उदाहरण

नीचे दिया गया कोड सैंपल, fieldId और labelId को अनसेट करने का तरीका बताता है फ़ील्ड की वैल्यू से जुड़े fileId डालें. उदाहरण के लिए, अगर किसी लेबल में टेक्स्ट और उपयोगकर्ता फ़ील्ड, दोनों को सेट करते समय, टेक्स्ट फ़ील्ड को अनसेट करने से वह लेबल से हट जाता है लेकिन उपयोगकर्ता के फ़ील्ड में कोई बदलाव नहीं होता. वहीं एक लेबल को हटाने से दोनों लेबल से जुड़ा टेक्स्ट और उपयोगकर्ता फ़ील्ड. ज़्यादा जानकारी के लिए, यह देखें किसी फ़ाइल से लेबल हटाना.

Java

LabelFieldModification fieldModification =
  new LabelFieldModification().setFieldId("FIELD_ID").setUnsetValues(true);

ModifyLabelsRequest modifyLabelsRequest =
  new ModifyLabelsRequest()
      .setLabelModifications(
          ImmutableList.of(
              new LabelModification()
                .setLabelId("LABEL_ID")
                .setFieldModifications(ImmutableList.of(fieldModification))));

ModifyLabelsResponse modifyLabelsResponse = driveService.files().modifyLabels("FILE_ID", modifyLabelsRequest).execute();

Python

field_modification = {'fieldId':'FIELD_ID','unsetValues':True}
label_modification = {'labelId':'LABEL_ID', 'fieldModifications':[field_modification]}

modified_labels = drive_service.files().modifyLabels(fileId="FILE_ID", body = {'labelModifications' : [label_modification]}).execute();

Node.js

/**
* Unset a label with a field on a Drive file
* @return{obj} updated label data
**/
async function unsetLabelField() {
  // 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 fieldModification = {
    'fieldId': 'FIELD_ID',
    'unsetValues': True,
  };
  const labelModification = {
    'labelId': 'LABEL_ID',
    'fieldModifications': [fieldModification],
  };
  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;
  }
}

इन्हें बदलें:

  • FIELD_ID: बदलाव किए जाने वाले फ़ील्ड का fieldId. पता लगाने के लिए fieldId, इसका इस्तेमाल करके लेबल को फिर से पाएं Google Drive Labels API.
  • LABEL_ID: बदलाव किए जाने वाले लेबल का labelId.
  • FILE_ID: उस फ़ाइल का fileId जिसके लिए लेबल हैं संशोधित.