在node.js中使用googleapi从google驱动器导出文件 [英] Exporting file from google drive using googleapi in node.js
问题描述
我正在使用googleapi从google驱动器导出文件.我的export.js中包含以下代码.当我运行此文件时,即使我已提供mimeType,它也会引发错误,提示"API返回错误:错误:必需参数:mimeType"
I am using googleapi to export the file from a google drive. I have the following code in my export.js. When I run this file, even though i have given the mimeType it throws an error saying "The API returned an error: Error: Required parameter: mimeType"
var drive = google.drive({
version: 'v3',
auth: auth
});
var dest = fs.createWriteStream('./public/data/myfile.txt');
drive.files.export({
fileId : fileID,
mimeType : 'text/plain'
}, function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
console.log('Received %d bytes', response.length);
fs.writeFileSync(dest, response);
});
推荐答案
Ohai!维护者在这里.当发生这种情况时,通常是因为googleapis
和google-auth-library
的版本之间存在某些不匹配.就代码而言,我们在这里有完整的工作副本:
Ohai! Maintainer here. When something like this happens, it's usually because there's some mismatch between the version of googleapis
and google-auth-library
. As far as the code is concerned, we have a full working copy here:
https://github .com/google/google-api-nodejs-client/blob/master/samples/drive/export.js
现在-关于该怎么做.您需要确保a.)您使用的是最新版本的googleapis
,b.)您的package.json中没有google-auth-library
.请尝试:
Now - on what to do. You need to make sure that a.) you are using the latest version of googleapis
, and b.) you DO NOT have google-auth-library
in your package.json. Please try:
$ npm uninstall --save google-auth-library
$ npm install --save googleapis@28
$ npm uninstall --save google-auth-library
$ npm install --save googleapis@28
给个镜头,让我知道它是怎么回事:)
Give that a shot and let me know how it goes :)
这篇关于在node.js中使用googleapi从google驱动器导出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!