cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Musicians, convert your MuseScore files to PDF to play music on the go! Learn more 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: 

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

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

isaacfink
New member | Level 2
Go to solution

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

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

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.

View solution in original post

4 Replies 4

Greg-DB
Dropbox Staff
Go to solution

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
New member | Level 2
Go to solution

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

Здравко
Legendary | Level 20
Go to solution

@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.

Greg-DB
Dropbox Staff
Go to solution

@isaacfink In addition to the one Здравко shared, you can find an example of running it manually using curl in the blog post here, and an example of running it in the JavaScript SDK here.

Need more support?