You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
ojdev
11 months agoExplorer | Level 4
Dropbox SDK Integration: Access Token Challenges
Hello everyone, I'm currently working on developing a server-side application (using TypeScript) that integrates with Dropbox among other functionalities. I've created an application in the app cons...
- 11 months ago
Would be enough something like:
this.fileClient = new Dropbox({ refreshToken: process.env.DROPBOX_REFRESH_TOKEN, clientId: process.env.DROPBOX_CLIENT_ID, clientSecret: process.env.DROPBOX_CLIENT_SECRET, selectUser: process.env.DROPBOX_USER, });
To avoid meaningless refresh (usually need no more than once for 4 hours) in frequent client object construction, sharing a DropboxAuth object might be useful. Something like:
this.auth = new DropboxAuth({ refreshToken: process.env.DROPBOX_REFRESH_TOKEN, clientId: process.env.DROPBOX_CLIENT_ID, clientSecret: process.env.DROPBOX_CLIENT_SECRET, }); ... this.fileClient = new Dropbox({ auth: this.auth, selectUser: process.env.DROPBOX_USER, });
Otherwise refresh will be executed on every client construction and if you just perform a single API call, the needed overall time will be doubled - decreased efficiency. To work the last, you need to keep 'auth' object global and shared throughout all your code (or saved with proper mutex protection), so the state won't start always from "zero". Of course this is optional - you decide whether improves your efficiency.
Good luck.
ojdev
Explorer | Level 4
Thank you for your response!
Following the mentioned process, I acquired a refresh token.
I need clarification: will initializing my Dropbox SDK client like this suffice?
this.fileClient = new Dropbox({
accessToken: process.env.DROPBOX_ACCESS_TOKEN,
refreshToken: process.env.DROPBOX_REFRESH_TOKEN,
selectUser: process.env.DROPBOX_USER,
});
Or, do I need to initialize it differently, like this?
this.fileClient = new Dropbox({
accessToken: process.env.DROPBOX_ACCESS_TOKEN,
refreshToken: process.env.DROPBOX_REFRESH_TOKEN,
clientId: process.env.DROPBOX_CLIENT_ID,
clientSecret: process.env.DROPBOX_CLIENT_SECRET,
selectUser: process.env.DROPBOX_USER,
});
Здравко
11 months agoLegendary | Level 20
Would be enough something like:
this.fileClient = new Dropbox({
refreshToken: process.env.DROPBOX_REFRESH_TOKEN,
clientId: process.env.DROPBOX_CLIENT_ID,
clientSecret: process.env.DROPBOX_CLIENT_SECRET,
selectUser: process.env.DROPBOX_USER,
});
To avoid meaningless refresh (usually need no more than once for 4 hours) in frequent client object construction, sharing a DropboxAuth object might be useful. Something like:
this.auth = new DropboxAuth({
refreshToken: process.env.DROPBOX_REFRESH_TOKEN,
clientId: process.env.DROPBOX_CLIENT_ID,
clientSecret: process.env.DROPBOX_CLIENT_SECRET,
});
...
this.fileClient = new Dropbox({
auth: this.auth,
selectUser: process.env.DROPBOX_USER,
});
Otherwise refresh will be executed on every client construction and if you just perform a single API call, the needed overall time will be doubled - decreased efficiency. To work the last, you need to keep 'auth' object global and shared throughout all your code (or saved with proper mutex protection), so the state won't start always from "zero". Of course this is optional - you decide whether improves your efficiency.
Good luck.
- ojdev11 months agoExplorer | Level 4
Thank you! You're a real life saver.
About Discuss Dropbox Developer & API
Make connections with other developers
795 PostsLatest Activity: 7 days agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!