1
我正在考慮批量處理Google Drive的請求。 Google Drive API提供了一個如何在Nodejs中批量請求的例子。然而,它使用異步和查找方法告訴我,它一次執行一個,我不清楚它是如何批量我的請求。如何在Nodejs中批量處理Google驅動器調用
Batching Google API calls可用。代碼示例如下。
var fileId = '1sTWaJ_j7PkjzaBWtNc3IzovK5hQf21FbOw9yLeeLPNQ';
var permissions = [
{
'type': 'user',
'role': 'writer',
'emailAddress': '[email protected]'
}, {
'type': 'domain',
'role': 'writer',
'domain': 'example.com'
}
];
// Using the NPM module 'async'
async.eachSeries(permissions, function (permission, permissionCallback) {
drive.permissions.create({
resource: permission,
fileId: fileId,
fields: 'id',
}, function (err, res) {
if (err) {
// Handle error...
console.error(err);
permissionCallback(err);
} else {
console.log('Permission ID: ', res.id)
permissionCallback();
}
});
}, function (err) {
if (err) {
// Handle error
console.error(err);
} else {
// All permissions inserted
}
});