谷歌驱动器file.update与双腿oauth返回好,但不能按预期工作

我有一个在console.developers.google.com中创build的服务帐户,并且我已经在高级设置>身份validation>pipe理OAuth客户端访问权下,将我所说的服务的客户端ID添加到我的全域代表团的admin.google.com中。

使用Google Nodejs api客户端和Google Nodejs auth库 ,我创build了一个jwt客户端,使用:

const jwtClient = new google.auth.JWT( key.client_email, null, key.private_key, [ 'https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/drive.file', 'https://www.googleapis.com/auth/drive.appdata', 'https://www.googleapis.com/auth/drive.scripts', 'https://www.googleapis.com/auth/drive.metadata' ], 'user@domain.com' ); 

 const google = require('googleapis'); const sheets = google.sheets('v4'); const drive = google.drive('v3'); 

我跑了

 async.waterfall( [ (callback) => { sheets.spreadsheets.create( { auth: jwtClient, resource: { properties: { title: 'Testing' } } }, (err, spreadsheet) => { console.log(spreadsheet); callback(err, spreadsheet.spreadsheetId) } ) }, (spreadsheetId, callback) => { drive.files.update( { auth: jwtClient, fileId: spreadsheetId, resource: { addParents: config.folder } }, (err, file) => { console.log(file); callback(err, file); } ) } ], (err, results) => { if (err) { console.log(err); res.status(400).send({ error: err.toString() }); } else { res.status(200).send("It lives!"); } } ); 

我第二次调用file.update的响应返回200,并返回文件的响应:

 { kind: 'drive#file', id: '<id-here>', name: 'Testing', mimeType: 'application/vnd.google-apps.spreadsheet' } 

但奇怪的是, addParents没有反映在Drive webapp上的文件细节中。

有任何想法吗。 我正在接触Google apis支持,并且在一周之内没有任何地方。 非常感谢您的帮助!

问题是addParents是查询参数,而不是Files资源中的字段。 因此,它应该被指定为fileId的同位fileId

 drive.files.update( { auth: jwtClient, fileId: spreadsheetId, addParents: config.folder }, ...