किसी फ़ाइल रिसॉर्स से लेबल दिखाना

इस पेज पर, Google Drive फ़ाइल संसाधन से खास लेबल वापस लाने का तरीका बताया गया है.

आपको कौनसे लेबल वापस चाहिए, यह बताने के लिए files.get तरीके का इस्तेमाल करें. इसके अलावा, फ़ाइल रिसॉर्स दिखाने वाले किसी भी तरीके का इस्तेमाल किया जा सकता है. अनुरोध का मुख्य हिस्सा खाली होना चाहिए.

कामयाब रहने पर, response body में File का एक इंस्टेंस शामिल होता है.

उदाहरण

यहां दिए गए कोड सैंपल में, खास लेबल का सेट दिखाने के लिए, fileId और labelId का इस्तेमाल करने का तरीका बताया गया है. includeLabels ऑब्जेक्ट, कॉमा लगाकर अलग किए गए आईडी की सूची है. fields पैरामीटर में मौजूद labelInfo ऑब्जेक्ट में, फ़ाइल पर सेट किए गए लेबल होते हैं. साथ ही, इन लेबल के लिए includeLabels में अनुरोध किया जाता है.

Java

File file = driveService.files().get("FILE_ID").setIncludeLabels("LABEL_ID,LABEL_ID").setFields("labelInfo").execute();

Python

file = drive_service.files().get(fileId="FILE_ID", includeLabels="LABEL_ID,LABEL_ID", fields="labelInfo").execute();

Node.js

/**
* Get a Drive file with specific labels
* @return{obj} file with labelInfo
**/
async function getFileWithSpecificLabels() {
  // 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});
  try {
    const file = await service.files.get({
      fileId: 'FILE_ID',
      includeLabels: 'LABEL_ID,LABEL_ID',
      fields:'labelInfo',
    });
    return file;
  } catch (err) {
    // TODO (developer) - Handle error
    throw err;
  }
}

इनकी जगह ये डालें:

  • FILE_ID: लेबल वाली फ़ाइल का fileId.
  • LABEL_ID: लौटाए जाने वाले लेबल का labelId. किसी फ़ाइल पर मौजूद लेबल ढूंढने के लिए, files.listLabels तरीके का इस्तेमाल करें.

नोट