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

Ghost Mjrm's avatar
Ghost Mjrm
Explorer | Level 4
12 months ago

How can i get lifetime Access Token

i have android app connected to my Dropbox folder using access token but every 4 hour should i edit my code and input the new access token is there any method to make the app working 24h without any interact from me

and fix the message that show access token error uploading to Dropbox: expired access token

 

 

private void uploadToDropbox(File photoFile) {
if (photoFile == null || !photoFile.exists()) {
runOnUiThread(() -> Toast.makeText(MainActivity.this, "Error: Photo file does not exist", Toast.LENGTH_SHORT).show());
return;
}

DbxRequestConfig config = DbxRequestConfig.newBuilder("Decamera").build();
DbxClientV2 client = new DbxClientV2(config, DROPBOX_ACCESS_TOKEN);

try {
String remotePath = "/Decamera/" + photoFile.getName();

try (InputStream in = new FileInputStream(photoFile)) {
client.files().uploadBuilder(remotePath)
.withMode(WriteMode.ADD)
.uploadAndFinish(in);

runOnUiThread(() -> Toast.makeText(MainActivity.this, "Photo uploaded to Dropbox", Toast.LENGTH_SHORT).show());
}

} catch (Exception e) {
e.printStackTrace();
runOnUiThread(() -> Toast.makeText(MainActivity.this, "Error uploading to Dropbox: " + e.getMessage(), Toast.LENGTH_SHORT).show());
}
}
private static final String DROPBOX_ACCESS_TOKEN = my access token

 

  • Ghost Mjrm, Be more careful when inspecting the code.

     


    Ghost Mjrm wrote:
    ... there is no offline ...

    Hm..🤔 Let's see where the OAuth starts here and what actually gets executed here. 🧐 Are you still thinking "there is no offline"? 🙂

     


    Ghost Mjrm wrote:
    ... or refresh token example

    Let's see where OAuth finish here and what actually it executes here. Ahhh... where was this refresh token... 😉

    Keep more attention on code reading.

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

    Ghost Mjrm, There is no way to get non expiring access token. As discussed before, you need to use refresh token instead. Refresh token doesn't expire automatic, so you can use it more than 24 hours. 😉 Use OAuth as Greg suggested there. Don't forget to set offline access.

    Good luck.

    • Ghost Mjrm's avatar
      Ghost Mjrm
      Explorer | Level 4
      Can you help me with that how can i edit my code to achieve that i‘m beginner and I don’t have that experience to do that so if you can give me the instructions step by step 🫡:rose:

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,882 PostsLatest Activity: 3 years 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!