cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Our friends over at the Dropbox Champions program have some really cool new updates for creatives and we are here to share it with you right here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Access token is expiring every day? How can i fix it?

Access token is expiring every day? How can i fix it?

Korefer87
New member | Level 2

Hi im using an html simple Form where i ask users to upload their documentation. Everything seems the work fine but after 1 day i get an error. I generate anothe acces token and seems to work fine again, but then after 1 day it fails again. How can i get an access token that will not expired or stop working?

// Subir archivos a Dropbox
var accessToken = 'ACCES TOKEN';
var dbx = new Dropbox.Dropbox({ accessToken: accessToken });

if (selfieFile) {
dbx.filesUpload({ path: '/' + selfieFile.name, contents: selfieFile })
.then(function(response) {
console.log('Selfie subida correctamente: ' + response.name);
})
.catch(function(error) {
console.error(error);
alert('Error al subir la selfie.');
});
} else {
alert('Por favor, selecciona un archivo de selfie.');
}

if (identificationFile) {
dbx.filesUpload({ path: '/' + identificationFile.name, contents: identificationFile })
.then(function(response) {
alert('Archivo subido correctamente: ' + response.name);
})
.catch(function(error) {
console.error(error);
alert('Error al subir el archivo.');
});
} else {
alert('Por favor, selecciona un archivo de identificación.');
}
2 Replies 2

Rich
Super User II

@Korefer87 wrote:

I generate anothe acces token and seems to work fine again, but then after 1 day it fails again. How can i get an access token that will not expired or stop working?


Dropbox uses short-lived access tokens that expire after a short time (about 4 hours). You need to use a refresh token to obtain new access tokens as they expire.

 

Greg-DB
Dropbox Staff

@Korefer87 Rich is correct. Dropbox issues short-lived access tokens, which expire after a few hours, and optional refresh tokens, which don't expire. Apps can get long-term access by requesting "offline" access, in which case the app receives a "refresh token" that can be used to retrieve new short-lived access tokens as needed, without further manual user intervention. Refresh tokens do not expire automatically and can be used repeatedly. You can find more information in the OAuth Guide and authorization documentation. There's a basic outline of processing this flow in this blog post which may serve as a useful example.
 
For examples of implementing this with the Dropbox JavaScript SDK, please refer to the examples included in the "examples" folder in the SDK. As long as you supply the necessary credentials, for instance, set the app key (a.k.a. client ID) and refresh token, like shown in this example for the JavaScript SDK, the SDK will actually handle refresh process for you automatically. (Note that the app secret is also required if the app does not use PKCE.) The SDK will automatically catch expired access token errors and call the API to get a new short-lived access token when needed.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Rich Super User II
What do Dropbox user levels mean?