@weborigami/gdrive
v0.0.5
Published
This package provides functions for treating a [Google Drive](https://www.google.com/drive/) folder as an [async tree](https://weborigami.org/async-tree/interface).
Downloads
4
Readme
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:
- Open https://console.cloud.google.com.
- Select "Create Project" and fill out the details.
- From the side nav bar select "APIs & Services", then "API Library".
- Select "Google Drive API".
- Click "Enable".
- Click "Create Credentials". If asked what type, select "Service account".
- When asked "What data will you be accessing?", select "Application data".
- When asked to name the service account, enter anything that reflects the project you're creating.
- For "Role", select "Editor".
- Click "Done" to finish creating a service account.
- 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".
- If you want to work with data in Google Docs, do the same with the Google Docs API.
- Select the service account you just created.
- Click "Keys", then "Add Key", then "Create new key".
- Indicate that you want a JSON key, then "Create".
- This will download a .json file to your computer; move that file into your project and rename it
creds.json
. - It's important to not check this file into source control. E.g., add that to
.gitignore
.
Usage
- Use npm to install the main
@weborigami/origami
package and this@weborigami/gdrive
extension. - Obtain Google API credentials (above) and save the credentials as a file
creds.json
. - Create a folder in Google Drive and "Share" it so that anyone with the link can view it.
- 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. - 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