@weborigami/dropbox
v0.0.20
Published
This package provides functions for treating a [Dropbox](https://www.dropbox.com) folder as an [asynchronous map-based tree](https://weborigami.org/async-tree/interface). You can represent your Dropbox folder as a [network host connection](https://weborig
Readme
This package provides functions for treating a Dropbox folder as an asynchronous map-based tree. You can represent your Dropbox folder as a network host connection so that you can read and write files directly to it.
Install the extension
In the command line, install the extension in your project with:
$ npm install @weborigami/dropboxObtaining Dropbox credentials
This extension requires an API key from Dropbox. Like most cloud platforms, gaining programmatic access is ridiculously complicated and requires you to navigate a little maze of twisting passages.
As of June 2024, the process to obtain a key is roughly:
- Open https://www.dropbox.com/developers.
- Click "Create apps".
- Fill out the fields to create a new app. As of June 2024, there is only one API choice; "Scoped access". For "type of access you need", select "Full dropbox". Give your app a name. Then click "Create app".
- Dropbox will show the settings page for your new app. Click the Permissions tab.
- Check the boxes for
files.metadata.readandfiles.content.read. If you want to be able to write files to Dropbox, also checkfiles.content.write. Then click Submit to save your changes. - Return to the Settings tab.
- In your code editor, create a new file called
creds.json, which will store the information you need to connect to Dropbox. In the file, paste:
{
"app_key": "",
"app_secret": "",
"refresh_token": ""
}- Copy the "App key" and "App secret" values from the Dropbox settings page into the corresponding fields in
creds.json. - You will now need to jump through several hoops to get a
refresh_token. The first step is obtain an "Access Code". Navigate to the following URL, substituting your "App key" from the Dropbox settings page:
https://www.dropbox.com/oauth2/authorize?client_id=<App key>&response_type=code&token_access_type=offline- Dropbox will ask you if you want to grant access to the application; agree to that.
- Dropbox should display an Access Code. Copy that value.
- You now need to convert that Access Code into a refresh token. In a command window, enter the following command, substituting the "App key", "App secret", and your new "Access code":
curl https://api.dropbox.com/oauth2/token \
-d code=<Access code> \
-d grant_type=authorization_code \
-u <App key>:<App secret>- You should get back a JSON result that contains a
refresh_tokenvalue like this:
{
"access_token": "...",
"token_type": "bearer",
"expires_in": 14400,
"refresh_token": "<some string of letters and numbers>",
...
}- Copy the
refresh_tokenvalue from that result and paste it intorefresh_tokenfield in thecreds.jsonfile. - Add the
creds.jsonfile to.gitignore. Don't check credential files into source control!
Create a file to represent the network host connection
Create a file called dropbox.ori that will represent your authenticated access to Dropbox. Paste in the following:
package:@weborigami/dropbox(creds.json)By default this will represent your entire Dropbox account. If you only want to point to a specific folder, add a path option to creds.json.
{
"app_key": "<app key goes here>",
"app_secret": "<app secret goes here>",
"path": "<path goes here>",
"refresh_token": "<refresh token goes here>"
}The path should be a string indicating a Dropbox folder, e.g., path/to/folder.
Test your connection
After creating a file like dropbox.ori to represent your Dropbox account, you can test it by using Tree.keys to list out the top level files and subfolders:
$ ori keys dropbox.ori
assets/
posts/
feed.json
index.html
README.mdOnce you've tested that your connection works, you can read and write files; see using the network connection.
