A small "sandbox" (a place to play) repo to demo one of the many ways of setup archieml with google auth library and google cloud. I'm hoping this is a helpful collection of examples and documentaiton to help you get up and running with google docs with archieml content in it. The goal is to keep the examples super simple so you can run with your own ideas! ❤
BEFORE you can run any of the examples in this repo, you'll need to do a few things:
- Get stuff setup in google cloud
- follow these instructions to Create a project using google cloud > create a service account > enable billing and the google drive api
- Get yourself setup to make auth'd requests from this repo
- depending on how you roll, you can choose ONE of these instructions to follow or talk to an informed friend about how to permission a node.js project to talk to the google drive api
- Create a gdoc > add some archieml > and give your service account permissions to read that specific gdoc
- follow these instructions here at step 3
It's as easy as 1,2,3 🎶! But seriously, all the auth and permissions stuff can be a drag and really hard to parse through especially if you're not familiar with google cloud and how they handle auth/permissions. Hopefully some of these docs are useful for you ❤
Once you've taken care of all the google cloud/auth/permissions nonsense, then you can run the demo app or run the simple example script to get a single doc
(process as of April 7, 2024)
- Create a new project:
- go to google cloud console https://console.cloud.google.com/ > dropdown: select project > new project > project name: "name-it-whatever-you-want" > project id (under the input) click "edit" > project id: "name-it-whatever-you-want"
- create service account
- go to IAM & Admin https://console.cloud.google.com/iam-admin/iam > then to service accounts https://console.cloud.google.com/iam-admin/serviceaccounts > click: "create service account" > add in a service account name, account id, and description
- Set the role of the service account to: "viewer"
- enable billing
- go to https://console.cloud.google.com/billing/ > enter your payment info
- enable
google drive api
--- go to https://console.cloud.google.com/apis/library/drive.googleapis.com > click:
enable
- go to https://console.cloud.google.com/apis/library/drive.googleapis.com > click:
After following the steps above, you need to decide how you want your app to get the application credentials to be able to read your files from google drive. You can follow these guides -- YOU ONLY NEED TO CHOOSE OF THESE
- Google auth with application default credentials (RECOMMENDED)
- Google Auth with local service account credentials
!!! You MUST complete one of the above so that the google-auth-library can successfully authenticate and get the authorizations it needs to talk to google drive!
Create and permission your google doc and add some archieml in!
- create a google doc
- go to google drive drive.google.com > create a folder where you want to store your docs (e.g. a folder called "archieml") > create a new google doc
- add some archieml formatted text
- e.g. copy and paste the value of
textInGoogleDoc
from the./__fixtures/helloWorld.js
file into your google doc
- e.g. copy and paste the value of
- update the docs permissions:
- click: share > add the service account email you want to permission
This is a tiny node/express app that uses the credentials from your service account to auth requests using the google-auth-library to get the text parsed from a google doc as json using archieml
Make sure you setup google cloud and have a google doc permissioned and ready to use. To do this:
- make sure you have completed:
Before Getting Started: Set up Google Cloud and create a google doc with archieml in it
Assuming all went well above, this step gets your app setup to run.
Install the dependencies to run this app
cd archieml-sandbox
npm i
This is a super simple node/express app that returns a parse JSON representation of a the content from a google doc.
npm run start
# see the magic at: http://localhost:3000
See your parsed gdoc by passing your gdoc id to: http://localhost:3000/doc/:docId
, for example, if your google doc url looks like this:
https://docs.google.com/document/d/blah1blah2hello3yo4/edit
you can see the contents of that gDoc by making a request for blah1blah2hello3yo4
http://localhost:3000/doc/blah1blah2hello3yo4
See
/examples
for other examples
This example will just get a single doc log the parsed result. Make sure you've completed the steps above in the setup section so that you have the credentials needed to run this script.
# !!! first update `gdoc` id in the script with your own!
node -r dotenv/config examples/get-single-doc.js
I have no idea when I'll get to these, but just logging down some ideas
- Google Sheets: add examples pulling data from google sheets
- Google Docs: add example using dropdowns
- Google Docs: add example using suggestion mode
- Created by @joeyklee
- Based on the demo in archieml-js/examples
- Made possible by ArchieML and all the contributors and people who have built other helpful tools to support archieml in their own work and organizations