הצגת רשימה של תוויות בקובץ

לארגון יכולות להיות כמה תוויות, ולכל תוויות יכולים להיות מספר שדות. בדף הזה מוסבר איך לראות את כל התוויות בקובץ יחיד ב-Google Drive.

כדי להציג את תוויות הקבצים, משתמשים ב-method‏ files.listLabels. גוף הבקשה צריך להיות ריק. ה-method מקבלת גם את פרמטר השאילתה האופציונלי maxResults כדי להגדיר את המספר המקסימלי של תוויות שיוחזרו בכל דף. אם לא מצוין, יוצגו 100 תוצאות.

אם הפעולה בוצעה בהצלחה, גוף התגובה יכיל את רשימת התוויות שחלות על הקובץ. הם קיימים באובייקט items מסוג Label.

דוגמה

דוגמת הקוד הבאה מראה איך להשתמש ב-fileId של התווית כדי לאחזר את התוויות הנכונות.

Java

List<Label> labelList =
labelsDriveClient.files().listLabels("FILE_ID").execute().getItems();

Python

label_list_response = drive_service.files().listLabels(fileId="FILE_ID").execute();

Node.js

/**
* Lists all the labels on a Drive file
* @return{obj} a list of Labels
**/
async function listLabels() {
  // 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 labelListResponse = await service.files.listLabels({
      fileId: 'FILE_ID',
    });
    return labelListResponse;
  } catch (err) {
    // TODO (developer) - Handle error
    throw err;
  }
}

מחליפים את FILE_ID בfileId של הקובץ שרוצים לקבל את רשימת התוויות שלו.