Get the contents of a Google Drive spreadsheet in CSV format

I am trying to get the contents of a Google Drive table file through node.js. I use google-api-nodejs-client to get access_token and node-google-drive to get file_id .

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

When I logged in to Google Drive, and I go to this URL above, it loads the table in CSV format. When I try to go to this URL incognito, it shows the login page, which is the same page that I get in the body of my request in 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); }); 

I tried to send the Authorization header, but I still get the HTML response. Contains Sorry, the file you have requested does not exist.

+4
source share
1 answer

Use this: https://github.com/jpillora/node-edit-google-spreadsheet

Example

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

Hi,

/ t

+3
source

Source: https://habr.com/ru/post/1498089/


All Articles