@weborigami/gdrive

0.0.5 • Public • Published

This package provides functions for treating a Google Drive folder as an async tree.

It also allows you to read a Google Sheets spreadsheet range or Google Docs document as plain JSON.

Obtaining Google API credentials

This extension requires an API key from Google. Like most cloud platforms, gaining programmatic access is ridiculously complicated and requires you to navigate a maze of twisty little passages, all alike.

As of March 2024, the process to obtain a key is roughly:

  1. Open https://console.cloud.google.com.
  2. Select "Create Project" and fill out the details.
  3. From the side nav bar select "APIs & Services", then "API Library".
  4. Select "Google Drive API".
  5. Click "Enable".
  6. Click "Create Credentials". If asked what type, select "Service account".
  7. When asked "What data will you be accessing?", select "Application data".
  8. When asked to name the service account, enter anything that reflects the project you're creating.
  9. For "Role", select "Editor".
  10. Click "Done" to finish creating a service account.
  11. If you want to work with data in Google Sheets, you'll need to enable that API as well. From the side nav bar, select "APIs & Services", then "API Library". Search for "Google Sheets API", click that, then click "Enable".
  12. If you want to work with data in Google Docs, do the same with the Google Docs API.
  13. Select the service account you just created.
  14. Click "Keys", then "Add Key", then "Create new key".
  15. Indicate that you want a JSON key, then "Create".
  16. This will download a .json file to your computer; move that file into your project and rename it creds.json.
  17. It's important to not check this file into source control. E.g., add that to .gitignore.

Usage

  1. Use npm to install the main @weborigami/origami package and this @weborigami/gdrive extension.
  2. Obtain Google API credentials (above) and save the credentials as a file creds.json.
  3. Create a folder in Google Drive and "Share" it so that anyone with the link can view it.
  4. Identify the ID of that folder. When you open the folder in the browser, the URL will look like https://drive.google.com/drive/u/0/folders/<id>, where the <id> is a string of letters and numbers.
  5. Create a file called test.ori that will represent your authenticated access to that folder. Inside the file, paste this line:
package:@weborigami/gdrive/auth(creds.json)/<id goes here>

You can then use the Origami CLI to get a list of the files in the Google Drive folder:

$ ori @keys test.ori/
... list of file names in the Google Drive folder...

Or copy the Google Drive folder to a local folder called copied:

$ ori @copy test.ori, @files/copied

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.51latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.51
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i @weborigami/gdrive

Weekly Downloads

1

Version

0.0.5

License

none

Unpacked Size

26 kB

Total Files

17

Last publish

Collaborators

  • jan.miksovsky