5

我正在尝试通过 node.js 获取 Google Drive 电子表格的文件内容。我正在使用google-api-nodejs-client来获取access_tokennode-google-drive模块来获取file_id.

"https://docs.google.com/feeds/download/spreadsheets/Export?key="+file_id+"&exportFormat=csv&gid=0"

当我登录 Google Drive 并转到上面的 URL 时,它会以 CSV 格式下载电子表格。当我尝试以隐身方式访问该 URL 时,它会显示一个登录页面,这与我在 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.

4

1 回答 1

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);
  });
}

问候,

/吨

于 2013-11-08T10:15:03.837 回答