We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

Korefer87's avatar
Korefer87
New member | Level 2
5 months ago

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

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.');
}
  • Rich's avatar
    Rich
    Icon for Super User II rankSuper 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's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox 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.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,878 PostsLatest Activity: 2 hours ago
326 Following

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 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!