download-google-spreadsheet
v0.1.1
Published
Download your Google Spreadsheets with Node.js.
Downloads
143
Maintainers
Readme
download-google-spreadsheet 0.1.1
Download your Google Spreadsheets with Node.js.
Usage
Get the API key:
- Visit Google Developers Console and create a project
- Go to
Overviewthen get intoDrive APIandEnable - Then
API Manager / Credentials / Create credentials / OAuth client ID - Set
Application typetoWeb application - Set
Authorized redirect URIstohttp://localhost:3477/or your own value - Continue to
Createand save your new credential
Then export to environment variables: DGSS_CLIENT_ID, DGSS_CLIENT_SECRET and DGSS_REDIRECT_URL. Or save them into .env under the working directory if you want, then:
$(npm bin)/download-google-spreadsheet '[{"fileId":"11KmsfhX7M0q3dwLSYiUAIIbov8qHvvhLcxqJzv9o1Pw","gid":"0"}]'If no cached token .dgsstoken can be found under current directory, you will be prompted to a Google OAuth page for you to authorize your API key to access the spreadsheets. The token will then be cached and you will not be prompted again until the expiration.
After that, the test spreadsheet will be downloaded into current working directory as 0.csv. The CSV file will be named as gid by default if there is no dest attribute defined for that sheet.
You can find the fileId and gid attributes from the link to your spreadsheet:
https://docs.google.com/spreadsheets/d/11KmsfhX7M0q3dwLSYiUAIIbov8qHvvhLcxqJzv9o1Pw/edit#gid=0
API
var downloadGoogleSpreadsheet = require('download-google-spreadsheet');
var sheets = [{
dest: './somedir/test.csv',
fileId: '11KmsfhX7M0q3dwLSYiUAIIbov8qHvvhLcxqJzv9o1Pw',
gid: '0',
}];
var opts = {
id: '686354652584-fule4tvfhelci96apnb368bsu3d1st9c.apps.googleusercontent.com',
redirect: 'http://localhost:3477/',
secret: 'OeBRLzWNkwMOdjDe5HyHqIiZ',
};
downloadGoogleSpreadsheet(sheets, opts, function (err) {
if (err) throw err;
console.log('Done.');
});Options
idGoogle OAuth client IDredirectMust be one of theAuthorized redirect URIsin credential settingssecretGoogle OAuth client secret
Development
npm run dev, code ./src/**/*.js, then ./bin/download-google-spreadsheet.js to try.
Releases
| Date | Version | Description | |------------|---------|-----------------| | 2016-03-28 | 0.1.1 | Fix callback | | 2016-03-27 | 0.1.0 | Initial release |
TODOs
- Support
stdinand pipe - Support CLI-only environment
- Show feedbacks to screen
- Expose more options
- Update build script to produce readable scripts
- Update readme
- Cache multiple tokens for multiple spreadsheets
- Code linting
- Test
