download-google-spreadsheet
v0.1.1
Published
Download your Google Spreadsheets with Node.js.
Downloads
45
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
Overview
then get intoDrive API
andEnable
- Then
API Manager / Credentials / Create credentials / OAuth client ID
- Set
Application type
toWeb application
- Set
Authorized redirect URIs
tohttp://localhost:3477/
or your own value - Continue to
Create
and 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
id
Google OAuth client IDredirect
Must be one of theAuthorized redirect URIs
in credential settingssecret
Google 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
stdin
and 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