Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@almost
Created August 28, 2012 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save almost/3496612 to your computer and use it in GitHub Desktop.
Save almost/3496612 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 ---')
});
});
// You also have dropboxOAuth.post and dropboxOAuth.delete and dropboxOAuth.put as you do for Node's http lib
@AaronAcerboni
Copy link

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

https://gist.github.com/3514519

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