Organisasi Anda dapat memiliki beberapa label, dengan label yang memiliki sejumlah kolom. Halaman ini menjelaskan cara mencantumkan semua label pada satu file Google Drive.
Untuk mencantumkan label file, gunakan metode
files.listLabels. Isi permintaan harus kosong. Metode ini juga menggunakan parameter kueri opsional maxResults untuk menetapkan jumlah maksimum label yang akan ditampilkan per halaman. Jika tidak ditetapkan, 100 hasil akan ditampilkan.
Jika berhasil, isi respons
akan berisi
daftar label yang diterapkan ke file. Ini ada dalam objek items berjenis
Label.
Contoh
Contoh kode berikut menunjukkan cara menggunakan fileId label untuk mengambil label yang benar.
Java
List<Label> labelList = labelsDriveClient.files()
.listLabels("FILE_ID")
.execute()
.getLabels();
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;
}
}
Ganti FILE_ID dengan fileId file yang labelnya ingin Anda
cantumkan.