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

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

כדי להציג רשימה של תוויות קבצים, משתמשים ב-method files.listLabels. גוף הבקשה חייב להיות ריק. השיטה גם משתמשת בפרמטר האופציונלי של השאילתה 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 של הקובץ שעבורו רוצים את רשימת התוויות.