dropbox-v2-api
dropbox-v2-api copied to clipboard
Tidy async/await solution for avoiding callback hell
For anyone using modern browsers/node, this should help to make the examples usable.
The secret lies in util.promisify!
const util = require('util')
const dbAccessToken = 'YOURTOKEN'
const dropbox = require('dropbox-v2-api').authenticate({ token: dbAccessToken })
const dbSync = util.promisify(dropbox)
async function getAcc () {
const params = { resource: 'users/get_current_account' }
try {
return (await dbSync(params))
} catch (err) {
console.error(err)
}
}
async function test () {
console.log(await getAcc())
}
test()
Hope this helps someone else avoid a good couple of hours struggling with why the "returns" were returning" undefined"!
Thanks!
However this does not work for files/list_folder
, returns search_file_metadata
thus crashing when writing the stream