JSPM

  • Created
  • Published
  • Downloads 4048
  • Score
    100M100P100Q175887F
  • License ISC

NodeJS Dropbox v2 API wrapper

Package Exports

  • dropbox-v2-api

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dropbox-v2-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

dropbox-v2-api

Dropbox API v2 wrapper for nodejs.

The dropbox-v2-api module is generated dynamically - it's based on Dropbox API description JSON file which is an representation of Dropbox API v2 HTTP methods description, retrived from official documentaion webpage.

Get started

var dropbox = require('dropbox-v2-api');

Auth

  • using token
dropbox.authenticate({
    token: 'your token'
});
//set credentials
var oauth = dropbox.authenticate({
    client_id: 'APP_KEY',
    client_secret: 'APP_SECRET',
    redirect_uri: 'REDIRECT_URI'
});
//generate and visit authorization sevice 
var authUrl = oauth.generateAuthUrl();
//after redirection, you should receive code
oauth.getToken(code, function(err, response){
  //you are authorized now!
});

Full API showcase

dropbox({
    resource: (string),
    parameters: (object?),
    readStream: (readable stream object?)
}, function(err, result){
    if(err){ return console.log('err:', err); }
    console.log(result);
});
  • resource (string) represent API target. It contains Dropbox's namespace and method name. eg. 'users/get_account', 'users/get_space_usage', 'files/upload', 'files/list_folder/longpoll', 'sharing/share_folder' more at official documentation
  • parameters (object?) optional parameters, depends on resource field
  • readStream (readable stream?) Upload-type requests should contains readStream field, which is readable stream

API call examples

get_current_account see docs

dropbox({
    resource: 'users/get_current_account'
}, function callback(err, response){
    if(err){ return console.log('err:', err); }
    console.log(response);
});

upload see docs

Upload-type requests should contains readStream field, which is readable stream

dropbox({
    resource: 'files/upload',
    parameters: {
        path: '/dropbox/path/to/file.js'
    },
    readStream: fs.createReadStream('path/to/file.js')
}, function(err, result){
    if(err){ return console.log('err:', err); }
    console.log(result);
});

download see docs

Download-type requests return writableStream

dropbox({
    resource: 'files/download',
    parameters: {
        path: '/dropbox/image.jpg'
    }
}, function(err, result){
    if(err){ return console.log('err:', err); }
    console.log(result);
}).pipe( fs.createWriteStream('./image.jpg') );

get_metadata see docs

dropbox({
    resource: 'files/get_metadata',
    parameters: {
        path: '/dropbox/path/to/file.js',
        include_media_info: false
    }
}, function(err, result){
    if(err){ return console.log('err:', err); }
    console.log(result);
});