בדף הזה מוסבר איך להחזיר תוויות ספציפיות ממשאב קובץ ב-Google Drive.
כדי לציין אילו תוויות רוצים לאחזר, משתמשים בשיטה files.get
או בכל שיטה שמחזירה משאב קובץ. גוף הבקשה חייב להיות ריק.
אם הפעולה מצליחה, גוף התגובה מכיל מופע של File
.
דוגמה
דוגמת הקוד הבאה מראה איך להשתמש ב-fileId
וב-labelId
כדי להחזיר את קבוצת התוויות הספציפיות. האובייקט includeLabels
הוא רשימה של מזהי חשבונות מופרדים בפסיקים. האובייקט labelInfo
בפרמטר fields
מכיל תוויות שהוגדרו בקובץ וביקשת ב-includeLabels
.
File file = driveService.files().get("FILE_ID ").setIncludeLabels("LABEL_ID ,LABEL_ID ").setFields("labelInfo").execute();
file = drive_service.files().get(fileId="FILE_ID ", includeLabels="LABEL_ID ,LABEL_ID ", fields="labelInfo").execute();
/**
* 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
של התווית להחזרה. כדי לאתר את התוויות בקובץ, משתמשים ב-methodfiles.listLabels
.
הערות
- כל שיטה שמחזירה משאב קובץ תומכת בשדה
includeLabels
ובפרמטר השאילתה. לדוגמה,files.copy
,files.list
ו-files.update
.