Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 73 lines (48 sloc) 2.571 kB
9fd1be1 @evnm Started README content.
authored
1 # dropbox-node
2
3 An OAuth-enabled node.js client for working with the Dropbox API.
aaae1c7 @evnm Added incomplete disclaimer to README.
authored
4
6232247 @evnm Added installation and todo blurbs.
authored
5 ## Installation
6
ae5b4af @evnm Wrote usage and testing sections.
authored
7 dropbox-node depends on [`node-oauth`](http://github.com/ciaranj/node-oauth).
6232247 @evnm Added installation and todo blurbs.
authored
8
ae5b4af @evnm Wrote usage and testing sections.
authored
9 To install, download the module and create a symlink in `~/.node_libraries`:
6232247 @evnm Added installation and todo blurbs.
authored
10
11 $ ln -s /path/to/dropbox-node/ ~/.node_libraries/dropbox-node
12
ae5b4af @evnm Wrote usage and testing sections.
authored
13 ## Usage
14
15 To start, you'll need to grab a consumer key and secret from [developers.dropbox.com](developers.dropbox.com).
16
17 ### OAuth credentials and object construction
18
19 First construct an OAuth client and acquire a valid access token and access token secret pair.
20
21 var sys = require('sys'),
22 DropboxClient = require('dropbox-node').DropboxClient,
23 OAuth = require('oauth').OAuth,
24 oauth = new OAuth('http://api.dropbox.com/0/oauth/request_token',
25 'http://api.dropbox.com/0/oauth/access_token',
26 consumer_key, consumer_secret,
27 '1.0', null, 'HMAC-SHA1')
28
29 Now create a DropboxClient object.
30
31 var dropbox = new DropboxClient(oauth, access_token, access_token_secret)
32
33 ### Calling API methods
34
35 `dropbox-node` provides methods covering [each of the Dropbox API methods](https://www.dropbox.com/developers/docs), excluding access token acquisition and account creation.
36
37 For example, to fetch and print the display name and email address associated with your account:
38
39 dropbox.getAccountInfo(function(err, data) {
40 if (err) console.log('Error: ' + sys.inspect(err))
41 else {
42 var data_json = eval('(' + data + ')')
43 console.log(data_json.display_name + ', ' + data_json.email)
44 }
45 })
46
47 Here's an example where we upload a file and remotely move it around before deleting it.
48
49 // Upload foo.txt to the Dropbox root directory.
50 dropbox.putFile('foo.txt', '', function(err, data) {
51 if (err) console.log('Error: ' + sys.inspect(err))
52 })
53
54 // Move it into the Public directory.
55 dropbox.move('foo.txt', 'Public/foo.txt', function(err, data) {
56 if (err) console.log('Error: ' + sys.inspect(err))
57 })
58
59 // Delete the file.
60 dropbox.delete('Public/foo.txt', function(err, data) {
61 if (err) console.log('Error: ' + sys.inspect(err))
62 })
63
64 ## Testing
65
66 `dropbox-node` depends on [`jasmine-node`](http://github.com/mhevery/jasmine-node) for testing. Note that the currently-implemented tests are trivial at best.
67
68 Run specs with `node specs.js` from the root `dropbox-node` directory.
69
6232247 @evnm Added installation and todo blurbs.
authored
70 ## TODO
71 * Improve test coverage.
ae5b4af @evnm Wrote usage and testing sections.
authored
72 * Add ability to interact with application sandboxes.
Something went wrong with that request. Please try again.