cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Tell us what you want to see on the Community here!
Close

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: 

Android - Unable to save the login in my android app

Highlighted

Android - Unable to save the login in my android app

Explorer | Level 3

Hi,

I am able to log the user in and retrieve the access token the first time and store it using SharedPreferences. However,  I want the users to log in automatically the next time they open my app (retrieve the access token silently).

I can always retrieve the access token stored in the app's local storage (SharedPreferences) but it might not be valid after a few hours/days. Is there a way to check if the access token in the local storage is valid and if not, retrieve a new access token without the user entering their dropbox credentials again.

 

Below is my code for retrieving the access token the first time:

 

private void dropboxLogin() {
        System.out.println("First Login");
        Auth.startOAuth2Authentication(MainActivity.this, APP_KEY);
} @Override protected void onResume() { super.onResume(); SharedPreferences prefs = getSharedPreferences("dropbox-sample", MODE_PRIVATE); String accessToken = prefs.getString("access-token", null); if (accessToken == null) { accessToken = Auth.getOAuth2Token(); if (accessToken != null) { prefs.edit().putString("access-token", accessToken).apply(); initAndLoadData(accessToken); } } else { initAndLoadData(accessToken); } System.out.println("Access Token: " + accessToken); String uid = Auth.getUid(); String storedUid = prefs.getString("user-id", null); if (uid != null && !uid.equals(storedUid)) { prefs.edit().putString("user-id", uid).apply(); } }

Note that I am using Dropbox API v2.

 

Thanks in advance!

 

1 Accepted Solution

Accepted Solutions
Highlighted

Re: Android - Unable to save the login in my android app

Dropboxer

While access tokens don't expire automatically, users can revoke access tokens at any time.

You can check if an access token is still currently valid by attempting an API call, such as getCurrentAccount.

If the access token is no longer valid though, it's not possible to get a new one without sending the user through the app authorization flow again.

View solution in original post

1 Reply 1
Highlighted

Re: Android - Unable to save the login in my android app

Dropboxer

While access tokens don't expire automatically, users can revoke access tokens at any time.

You can check if an access token is still currently valid by attempting an API call, such as getCurrentAccount.

If the access token is no longer valid though, it's not possible to get a new one without sending the user through the app authorization flow again.

View solution in original post

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?