2017-09-13 50 views
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 
    } 
}); 

回答

0

TL; DR - 你不能。

看看他們的文檔和其他示例,其他每種語言都有一個「批處理對象」,用於添加個別請求。在他們的節點示例中沒有這樣的。他們的Javascript client有一個.newBatch()呼叫。

檢出他們的NodeJS Migration Guide(它也從v2 api鏈接)。相關報價:

批量請求在1.0之前是實驗性的。由於不受歡迎和不穩定,我們已經取消了對1.0批量請求的支持。

附註說明,批量處理似乎只會爲您帶來帶寬 - Google API仍會將您的配額與您的配額分開計數。

相關問題