Transfer files to dropbox from node js without browser based oauth authentication

元气小坏坏 提交于 2019-12-02 21:49:55

Took me a bit of testing, but it's possible.

First, you need to authenticate through the browser and save the token and token secret that are returned by Dropbox:

dbClient.authenticate(function(error, client) {
  console.log('connected...');
  console.log('token ', client.oauth.token);       // THE_TOKEN
  console.log('secret', client.oauth.tokenSecret); // THE_TOKEN_SECRET
  ...
});

Once you have the token and the secret, you can use them in the Dropbox.Client constructor:

var dbClient = new Dropbox.Client({
  key         : DROPBOX_APP_KEY,
  secret      : DROPBOX_APP_SECRET,
  sandbox     : false,
  token       : THE_TOKEN,
  tokenSecret : THE_TOKEN_SECRET
});

After that, you won't get bothered with having to authenticate through a browser anymore (or at least not until someone runs the code again without the token and the secret, which will make Dropbox generate a new token/secret pair and invalidate the old ones, or the apps credentials are revoked).

Or you can just use the Implicit grant and get the oauth token.

        var client = new Dropbox.Client({
            key: "xxxxx",
            secret: "xxxxx",
            token:"asssdsadadsadasdasdasdasdaddadadadsdsa", //got from implicit grant
            sandbox:false
        });

No need to get to the browser at all.This line is no longer required!

   client.authDriver(new Dropbox.AuthDriver.NodeServer(8191));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!