node package manager
Orgs are free. Discover, share, and reuse code in your team. Create a free org »

googledoc-to-json

googledoc-to-json

Node.js library to read a Google Drive Doc and convert to JSON (via ArchieML)

This is a work-in-progress.

Install

npm install googledoc-to-json --save

Examples

CLI

$ npm install -g googledoc-to-json
$ googledoc-to-json <doc-id> -c config.json -o output.json

API

const GoogleDocToJSON = require('googledoc-to-json');
const config = require('./config.json'); // see 'Getting Credentials' below 
const gDocToJSON = new GoogleDocToJSON(config);
 
const options = {
    fileId: '1gTERIVPV_0yoMXc6mlBtBpNvaoH5pIU2IC-75V_Qcas',
    oAuthTokens: config.oAuthTokens
};
 
gDocToJSON.getArchieML(options, function (err, aml) {
    console.log('## ArchieML output', err, aml);
});

Getting credentials

  1. Got to https://console.developers.google.com
  2. Create an account
  3. In the right sidebar click Credentials
  4. Then click Create credentials, select oAuth client ID, select Web application
  5. Name your Web Application
  6. Enter https://developers.google.com/oauthplayground as an authorized redirect URLs
  7. Have your Client ID and Client secret ready
  8. Go to https://developers.google.com/oauthplayground/
  9. Under Step 1 authorize all Dirve API v3
  10. Click the Gear button in upper right of the page and check Use your own OAuth credentials
  11. Enter your Client ID and Client secret
  12. Click Authorize APIs
  13. Then request auth tokens, grab generated the refresh token.
  14. Create a config.json in your project with your info:
{
  "google": {
    "client_id": yourID,
    "client_secret": yourSecret,
    "oAuthTokens":{"refresh_token": yourRefreshToken},
    "redirect_urls":["http://localhost:####"]
  }
} 

Todos:

  • Add Mocha tests