Access token and Refresh token issue
panovvitalik opened this issue · 2 comments
Previously, I launched an OAuth dialog and received an access token from it:
String accessToken = Auth.getOAuth2Token();
Then I created client object with provided access token
DbxRequestConfig mConfig = DbxRequestConfig.newBuilder("my_tag").build();
DbxClientV2 mClient = new DbxClientV2(mConfig, accessToken );
And then used the client object for doawnloading and uploading, for example:
CreateFolderResult result = mClient.files().createFolderV2("/Example");
Today after a few hours after login. I recieved following error message:
Find error: {"error_summary": "expired_access_token/..", "error": {".tag": "expired_access_token"}}
I know that now all access tokens are short lived - its' very nice, and very usefull for some operations, unknown to me, but... What should I do?
I tried to use:
DbxRefreshResult result = mClient.refreshAccessToken();
String accessToken = result.getAccessToken());
But I recieved following error message:
"refreshAccessToken: Cannot refresh becasue there is no refresh token"
So the question is:
What should I change in my code today, for continue working with dropbox sdk?
p.s.
I use version 5.1.1 lib:
implementation 'com.dropbox.core:dropbox-core-sdk:5.1.1'
Based on the use of Auth.getOAuth2Token
, it sounds like this is for an Android app. If so, in order to request "offline" access to get and use a refresh token (which the SDK will actually do for you automatically when provided with a refresh token), make sure you're using the startOAuth2PKCE
method to start the authorization flow and then save the result accordingly. Here's where that starts in the new example, and here it is in the old example.
Thanks! It works.
// Launch OAuth login dialog
DbxRequestConfig requestConfig = new DbxRequestConfig(CLIENT_IDENTIFIER);
// We MUST provide here all needed scopes from App Permissions page: https://www.dropbox.com/developers/apps
List<String> scopes = ListUtils.createObjectList("account_info.read", "files.metadata.read", "files.content.write", "files.content.read");
Auth.startOAuth2PKCE(getContext(), DROPBOX_APP_KEY, requestConfig, scopes);
//...
// Get result object of Auth dialog
DbxCredential dbxCredential = Auth.getDbxCredential();
String sCredential = dbxCredential.toString()
//...
// Create client object by saved credential object
DbxCredential dbxCredential = DbxCredential.Reader.readFully(sCredential );
DbxRequestConfig config = DbxRequestConfig.newBuilder(CLIENT_IDENTIFIER).build();
DbxClientV2 mClient = new DbxClientV2(config, dbxCredential);
// Use client object for example create directory:
CreateFolderResult result = mClient.files().createFolderV2("/Example");