我正在尝试通过node.js获取Google Drive电子表格的文件内容。我使用google-api-nodejs-client获取access_token
和node-google-drive模块来获取file_id
。
"https://docs.google.com/feeds/download/spreadsheets/Export?key="+file_id+"&exportFormat=csv&gid=0"
当我登录Google云端硬盘并转到上面的网址时,会以CSV格式下载电子表格。当我尝试以隐身方式转到该网址时,它会显示一个登录页面,该页面与我在node.js中请求正文中的页面相同。
request({
"method":"get",
"url": "https://docs.google.com/feeds/download/spreadsheets/Export",
"qs":{
"key": key,
"exportFormat": "csv",
"gid": 0
},
"headers":{
"Authorization": "Bearer " + token
}
}, function(err, response, body){
console.log(response);
});
我尝试发送Authorization
标头,但我仍然收到HTML回复。包含Sorry, the file you have requested does not exist.
答案 0 :(得分:3)
使用此:https://github.com/jpillora/node-edit-google-spreadsheet
实施例
var Spreadsheet = require('edit-google-spreadsheet');
Spreadsheet.create({
debug: true,
username: [GOOGLE USERNAME],
password: [PASSWORD],
spreadsheetName: 'node-edit-spreadsheet',
worksheetName: 'Sheet1',
spreadsheetId: '[DOC ID]',
callback: run
});
function run(err, spreadsheet) {
if(err) throw err;
//receive all cells
spreadsheet.receive(function(err, rows, info) {
if(err) throw err;
console.log("Found rows:", rows);
console.log("With info:", info);
});
}
此致
/吨