Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AaronAcerboni/3514519 to your computer and use it in GitHub Desktop.
Save AaronAcerboni/3514519 to your computer and use it in GitHub Desktop.
How to make signed requests for Dropbox API in Node.JS using node-oauth (for Dan)
// I assume here that you have already done your oauth authentication with dropbox
// (maybe using everyauth) and you have the access_token and access_token_secret (which are per-user).
// You also need the consumer_key and consumer_secret values for your Dropbox API account (these should
// be part of you application configuration).
// Step 1: Create an oauth object (do this once and store it, you can use the same object over and over)
var OAuth= require('oauth').OAuth;
dropboxOAuth = new OAuth("https://api.dropbox.com/1/oauth/request_token",
"https://api.dropbox.com/1/oauth/access_token",
CONSUMER_KEY, CONSUMER_SECRET,
"1.0A", "IGNORE ME", "PLAINTEXT");
// Step 2: Whenever you want to make a request to the API you use the oauth object instead of
// Node's http lib. You need to pass in the token and secret for the user you're
// making the request on behalf of.
request = dropboxOAuth.get("https://api.dropbox.com/1/account/info", ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
request.addListener('response', function (err, response) {
response.addListener('data', function (chunk) {
console.log(chunk);
});
response.addListener('end', function () {
console.log('--- END ---')
});
});
request.end()
// You also have dropboxOAuth.post and dropboxOAuth.delete and dropboxOAuth.put as you do for Node's http lib
@AaronAcerboni
Copy link
Author

request.end () is required for 'response' listener to fire off

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment