@weborigami/gdrive
v0.0.16
Published
This package provides functions for treating a [Google Drive](https://www.google.com/drive/) folder as an [asynchronous map-based tree](https://weborigami.org/async-tree/interface).
Downloads
22
Readme
This package provides functions for treating a Google Drive folder as an asynchronous map-based 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.
- The new service account will have an email address. You'll need that later to give access to the 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/origamipackage and this@weborigami/gdriveextension. - 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. Alternatively, you can add the service account's email address (mentioned above) to the list of users that can access the folder. If you want to be able to write files to the folder, give the service account write access.
- 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.orithat 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 snapshot:
$ ori copy test.ori, files:snapshot