项目作者: filipedeschamps

项目描述 :
Authenticates with Google API and parse Google Docs to JSON or Markdown
高级语言: JavaScript
项目地址: git://github.com/filipedeschamps/parse-google-docs-json.git
创建时间: 2020-08-19T21:17:26Z
项目社区:https://github.com/filipedeschamps/parse-google-docs-json

开源协议:MIT License

下载


Parse Google Docs JSON

This Node.js module authenticates with Google API and parse Google Docs to human-readable JSON or Markdown without the need to use cumbersome methods like exporting it in HTML via Google Drive API and then parse it back to other formats.

Why

When you use Google Docs API V1, the body that comes with the documents.get method is completely fragmented. It’s a JSON that you need to recursively parse to get the document into human-readable format. For my luck, there’s a Gatsby plugin that internally has this implementation already: gatsby-source-google-docs. So I’ve extracted this implementation into this module and exposed it with a Service Authentication. For more information about this type of authentication, follow this tutorial: How to authenticate to any Google API

Warning

This module works like a charm, but it’s for personal use, primarily. It will follow semantic version best practices, but will not have any automated tests in the short term.

How to use

  1. const parseGoogleDocsJson = require("parse-google-docs-json");
  2. async function start() {
  3. const parsed = await parseGoogleDocsJson({
  4. documentId: "1ymKw2OGcMfc02XdEEWdy22a_zUAlCxyN3P5Ab4c",
  5. clientEmail: "service@iam.gserviceaccount.com",
  6. privateKey: "-----BEGIN PRIVATE KEY...",
  7. });
  8. console.log(parsed.toJson());
  9. console.log(parsed.toMarkdown());
  10. }
  11. start();

Environment variables

  1. clientEmail = process.env.PARSE_GOOGLE_DOCS_CLIENT_EMAIL
  2. privateKey = process.env.PARSE_GOOGLE_DOCS_PRIVATE_KEY