Kuruluşunuzun birden fazla etiketi olabilir ve etiketlerin istediğiniz sayıda alanı olabilir. Bu sayfada, tek bir Google Drive dosyasındaki tüm etiketlerin nasıl listeleneceği açıklanmaktadır.
Dosya etiketlerini listelemek için files.listLabels
yöntemini kullanın. İstek gövdesi boş olmalıdır. Yöntem, sayfa başına döndürülecek maksimum etiket sayısını ayarlamak için isteğe bağlı maxResults
sorgu parametresini de alır. Ayarlanmazsa 100 sonuç döndürülür.
Başarılı olursa yanıt gövdesi, bir dosyaya uygulanan etiketlerin listesini içerir. Bunlar, Label
türündeki bir items
nesnesi içinde bulunur.
Örnek
Aşağıdaki kod örneğinde, doğru etiketleri almak için etiketin fileId
özelliğinin nasıl kullanılacağı gösterilmektedir.
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 yerine, etiket listesini istediğiniz dosyanın fileId
değerini girin.