You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
Alex57600
4 years agoExplorer | Level 3
Dropbox SDK JS + Refresh token problem
Hello
Please, do you have any idea how i can manage this ? Each 4 hours i get "expired_access_token" and user must re-log.
I just upgrade my old Dropbox SDK JS to the last version 10.8.0 + I did the changes to be compatible.
I have one Cordova app (iOS/Android/Win10).
The goal of my app is to : 1. User connect on dropbox (long life), user set "working hours" on my app, then each day/week user save/load data to/from Dropbox.
Here's my code:
Connexion code:
// 1. I init Dropbox connexion
dbx = new Dropbox.Dropbox({
clientId: dropboxClientId
});
// 2. I get auth url with redirect (custom url scheme)
var dropboxRedirectUri = 'MYAPP://dropbox_callback';
dbx.auth.getAuthenticationUrl(
dropboxRedirectUri,
'',
'code',
'offline',
[
'files.content.write',
'files.content.read',
],
'user',
true
)
.then((authUrl) => {
dropboxCodeVerifier = dbx.auth.codeVerifier;
cordova.InAppBrowser.open(authUrl, '_system');
});
// 3. User is redirect to his web browser to logoff, then user is redirected to my app
function handleOpenURL(url) {
// I read the "code" send by Dropbox
if (getUrlVars(url).code) {
dbx.auth.setCodeVerifier(dropboxCodeVerifier);
dbx.auth.getAccessTokenFromCode(dropboxRedirectUri, getUrlVars(url).code)
.then((response) => {
// I get the "access_token" (starts with sl as short-life)
localStorage['dropbox_access_token'] = response.result.access_token;
})
.then((response) => {
... User is now connected
})
.catch((error) => {
alert(error);
});
}
// At this point, i also get "refresh_token", but I'm sorry i don't know how to use it.
// So, after that, for each user action (save/load) i connect to dropbox + i launch my // actions with this code:
dbx = new Dropbox.Dropbox({
accessToken: localStorage['dropbox_access_token']
});
dbx.filesUpload({...
Best regards
- Greg-DBDropbox Staff
To maintain long-term access, you'll need to request "offline" access, as you're doing, and then supply the app key (the app secret isn't needed since you're using PKCE) and refresh token. As long as you do so, the SDK will handle the refresh process for you automatically. You can find an example of setting the refresh token in this example.
- Alex57600Explorer | Level 3Hello
Thank you very much.
I will try asap.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,915 PostsLatest Activity: 5 hours agoIf 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!