Na tej stronie dowiesz się, jak zwracać konkretne etykiety z zasobu pliku na Dysku Google.
Aby określić, które etykiety chcesz pobrać, użyj metody
files.get
lub dowolnej metody, która zwraca zasób pliku. Treść żądania musi być pusta.
Jeśli operacja się uda, treść odpowiedzi będzie zawierała instancję File
.
Przykład
Poniższy przykładowy kod pokazuje, jak używać fileId
i labelId
, aby zwracać zbiór określonych etykiet. Obiekt includeLabels
to lista identyfikatorów rozdzielonych przecinkami. Obiekt labelInfo
w parametrze fields
zawiera etykiety ustawione w pliku i żądane w ramach parametru 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;
}
}
Zastąp następujące elementy:
- FILE_ID:
fileId
pliku zawierającego etykiety. - LABEL_ID:
labelId
etykiety do zwrócenia. Aby znaleźć etykiety w pliku, użyj metodyfiles.listLabels
.
Uwagi
- Każda metoda zwracająca zasób pliku obsługuje pole
includeLabels
i parametr zapytania. Na przykład:files.copy
,files.list
ifiles.update
.