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

Forum Discussion

isaacfink's avatar
isaacfink
New member | Level 2
2 years ago

Is it possible to get a permanent token for uploading files to one specific account?

I have the following workflow in my application

I am generating some files and I am saving it to a dropbox account, the files are only saved to one specific account and the app and account are under the same email/user

I keep getting expired access token when using the js sdk, is there a way to get around this? here is my code to upload files

 

 

 

 

const dropbox = require("dropbox");

const client = new dropbox.Dropbox({
  accessToken: token,
});

await client.filesUpload({
  path:'/folder/image.jpg',
  contents: buffer,
});

 

 

 

 

but that gives me an error after a couple of hours, I don't want to have to go through 0auth flow because this a simple node script and not a complete application

  • Dropbox is no longer offering the option for creating new long-lived access tokens. Dropbox is now issuing short-lived access tokens (and optional refresh tokens) instead of long-lived access tokens. You can find more information on this migration here.

    Apps can still get long-term access by requesting "offline" access though, 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 and can be store and re-used repeatedly. While you do need to use the OAuth app authorization flow to get a refresh token, this only needs to be done once per account. 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.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    Dropbox is no longer offering the option for creating new long-lived access tokens. Dropbox is now issuing short-lived access tokens (and optional refresh tokens) instead of long-lived access tokens. You can find more information on this migration here.

    Apps can still get long-term access by requesting "offline" access though, 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 and can be store and re-used repeatedly. While you do need to use the OAuth app authorization flow to get a refresh token, this only needs to be done once per account. 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.

    • isaacfink's avatar
      isaacfink
      New member | Level 2

      I is there an example of an 0auth flow? I would like to run it once locally so I can get the token

      • Здравко's avatar
        Здравко
        Legendary | Level 20

        isaacfink wrote:

        I is there an example of an 0auth flow? I would like to run it once locally so I can get the token


        Hi isaacfink,

        A good and simple example for running locally can be seen here. You have to follow all steps (without the last one; it's executed inside SDK). Since PKCE is no used there, you'll need pass refresh token, appkey, and appsecret, as Greg mentioned already.

        Good luck.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,876 PostsLatest Activity: 5 hours ago
325 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!