Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
lalomores
4 years agoHelpful | Level 5
"App Authentication" for App (without tokens). Yet another migration from long lived tokens question
Hi there! I see there have been a lot of questions in the forum on this topic, so I'll just cut to the chase.
My app is made in Meteor (NodeJS) and React. Clients of my app do not need to handle fi...
- 4 years ago
lalomores Just like with long-lived access tokens, the user needs to manually authorize the app once to get the refresh token, which can then be stored and re-used without further manual user interaction. In that example, you can see where the SDK returns the refresh token, which is then set on the client, on this line: https://github.com/dropbox/dropbox-sdk-js/blob/main/examples/javascript/simple-backend/code_flow_example.js#L38 . You can store and programmatically re-use that 'token.result.refresh_token' value similar to how you would store and programmatically re-use a long-lived access token.
The refresh token is used to programmatically retrieve new short-lived access tokens whenever needed, without the user necessarily present. Those new short-lived access tokens that get retrieved automatically are what are used to then make actual API calls, such as filesListFolder (or usersGetCurrentAccount, as in the example).
Anyway, while Dropbox and the Dropbox API aren't really designed to be used as a CDN, we do recommend using the official SDK(s) whenever possible for accessing the Dropbox API. And using the app folder access type whenever that works for the use case is also a best practice.
Greg-DB
Dropbox Community Moderator
4 years agoYes, that's correct. The API was designed with the intention that each user would link their own Dropbox account, in order to interact with their own files. While it is technically possible to always connect to just one account for all users, we do not officially support this, for various technical and security reasons.
I'll also pass this along as a request for a "Generate refresh token" option, as well as to clarify the token lifetime in the API v2 Explorer, but I can't promise if or when that might be implemented.
dwissing
4 years agoExplorer | Level 4
I have spent hours trying to get the API working. It worked great before the tokens started expiring every 4 hours. I have read everything I can find about this, but I can't piece it together. I have an app that need to access a dedicated Dropbox folder. I don't care who is using the app, and I don't want the users to need to authenticate. It worked well with the long term token I generated in the app console before that option was removed.
It seems like now I have to figure out how to build a separate app just to authorize and create the token. I would love to be able to generate a token from the app console similar to how we could before. This would save me many, many hours of work.
- Здравко4 years agoLegendary | Level 20
Hi dwissing,
Take a look on https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Issue-in-generating-access-token/td-p/592667 how you would be able do the same in regular terminal. 😉
Hope this helps.
- dwissing4 years agoExplorer | Level 4
So this shows how to refresh a token manually in terminal. My app is Vue.js. Current code is: import { Dropbox } from 'dropbox'
import { Dropbox } from 'dropbox' import axios from 'axios' async function get_thumbnail() { const dropbox_token = 'sl.**CODE**' const options = { format: 'jpeg', mode: 'strict', path: found_file_path.value, size: 'w64h64' } var dbx = new Dropbox({ accessToken: dropbox_token }) try { const response = await dbx.filesGetThumbnail(options) return response } catch (error) { console.log(error) } }
I can use the info you provided in a terminal to get a new access token, but how do I do it automatically?
- Здравко4 years agoLegendary | Level 20
dwissing wrote:...
I can use the info you provided in a terminal to get a new access token, but how do I do it automatically?
...
🙂 No, no, no... Seems my forwarding was too brief and no very clear.
On the page, I referred to above, entire work flow is described, not only initial authentication! The last part there, as you noticed, is refresh description. Since you are using Dropbox SDK, where refresh process is implemented internally, you don't need to do it by hand. 😁 In such a way you would do some job of SDK by hand.
The only thing you need to do is initialization of Dropbox client object using refresh token, instead of access token. That's it. In addition it's NOT good idea every time when need to perform particular operation, new object sets up (like you are doing now). This leads to efficiency lost. Better, set one client object at the beginning (with global view or so), keep it, and use it till the end.
Take a look here how you can initialize a client object using refresh token. 😉
Hope it's a bit more clear now.
- Здравко4 years agoLegendary | Level 20
Greg-DB wrote:... , so you can store and re-use them repeatedly.
Greg-DB, better let dwissing focus on the particular setup. No storage or reusage is need in particular case. The refresh token is available as a constant and can be used as a replacement for 'token.result.refresh_token', in particular.
- dwissing4 years agoExplorer | Level 4
Thank you.
I tried just replacing the access token with the refresh token in the dbx - new Dropbox() line, but that did not work.
The example you pointed to uses the key and secret in this command, along with "fetch". I am not familiar with fetch, but I get the following error:
TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
at Dropbox2.fetch (<anonymous>:1:876)
at dropbox.js:108:22import { Dropbox } from 'dropbox' import axios from 'axios' const config = { fetch, clientId: 'app_key', clientSecret: 'app_secret' } var dbx = new Dropbox(config) async function get_thumbnail() { const options = { format: 'jpeg', mode: 'strict', path: found_file_path.value, size: 'w64h64' } try { const response = await dbx.filesGetThumbnail(options) return response } catch (error) { console.log(error) } } - Здравко4 years agoLegendary | Level 20
Здравкоwrote:...
The only thing you need to do is initialization of Dropbox client object using refresh token, instead of access token.
...
dwissing wrote:...
I tried just replacing the access token with the refresh token in the dbx - new Dropbox() line, but that did not work.
...
Of course, what did you expect??? 🤔 Did you expect different way of initialization and replacement to be the same? Does referred example use refresh token just as an access token replacement? (or not exactly) 🤷
Where you are getting this 'fetch' from? 🧐 (take a look on the example once again) 😉
Where you are setting your refresh token actually??? 🤦 (focus on the enlightened line in the example, once again)
Ensharp your attention little bit! 🙂
- dwissing4 years agoExplorer | Level 4
The example you linked to above has this setup:
const fetch = require('node-fetch'); const app = require('express')(); const hostname = 'localhost'; const port = 3000; const config = { fetch, clientId: 'jg8wc1hfkvel6ql', clientSecret: 'f0i5w4e6mlbbme5', }; const { Dropbox } = require('dropbox'); // eslint-disable-line import/no-unresolved const dbx = new Dropbox(config);Instead of using an access token in the "new Dropbox()" command, they are using the above config including "fetch". I don't really understand how this works, or where I can put the refresh token in order to use it to create a new Dropbox object.
- Здравко4 years agoLegendary | Level 20
dwissing wrote:... I don't really understand how this works, or where I can put the refresh token in order to use it to create a new Dropbox object.
Ok, I'm putting the example with enlightened line here again. Can you explain what exactly this line is doing (exactly this, no any other)? What will change if you replace the argument there to your refresh token literal? 🤔
Don't go fast! Relax little bit (as much as need). When you get ready, take a look on the line. What are you seeing there, what this line does actually? What if you put this line at the beginning? (next client object creation)
- dwissing4 years agoExplorer | Level 4
Thank you. I think I have it now.
I was thinking that you needed to already have the authenticated token before creating the new Dropbox object.
I didn't realize you could create an un-authenticated dbx object, and the call a method on it to authenticate.
I appreciate your patience and help. 🙂
About Discuss Dropbox Developer & API
Make connections with other developers
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If 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, Facebook or Instagram.
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!