cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We've been busy working on some major updates to the Community, so check out what's changing, what’s staying the same and what you can expect from the Dropbox Community right 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 there any Java sdk method to generate access token on the run by taking app key and app secre

is there any Java sdk method to generate access token on the run by taking app key and app secret??

Reshma
Explorer | Level 3
Go to solution

Hello Dropbox team,


As Access token is expiring every 4 hours, we have to regenerate them every 4 hrs. This is becoming difficult to update the access code in my script manually. I'm looking for a Java SDK method that generate access token automatically every 4 hours by taking app key/app secret as input parameters. Could you suggest any sdk method or code sample that I can use to generate access token on the run in my script using app key/app secret. 

Any help would be highly appreciated !!

1 Accepted Solution

Accepted Solutions

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

Hi again @Reshma ,

Seems you have misunderstood me. You can't just place one type of token where other type is expected! In Java SDK a DbxCredential object should be used as a proxy (don't ask me why) for refresh token.

Hope it's a bit more clear now.

View solution in original post

7 Replies 7

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

Hi @Reshma ,

Every supported SDK do this automatically byself (without any additional method/function call). You just have to initialize your client object using refresh token instead of access token. 😉 That's it.

Hope this helps.

Reshma
Explorer | Level 3
Go to solution

Thanks for the suggestion. I have created a Refresh token using this curl

curl https://api.dropbox.com/oauth2/token -d code=<receivedcode>-d grant_type=authorization_code -u <Appkey>:<Appsecret>

Then I have initialized/created drop box client object with Refresh token in place of access token

 

private static final String REFRESH_TOKEN = "<REDACTED_REFRESH_TOKEN> -u <REDACTED_APP_KEY>:<REDACTED_APP_SECRET>";

 

// Create drop box client

DbxRequestConfig config = DbxRequestConfig.newBuilder("dropbox/AppToCreateIT's").build();
DbxClientV2 client = new DbxClientV2(config, REFRESH_TOKEN);

 

But unfortunately this dint work, it is throwing below error
Invalid authorization value in HTTP header "Authorization": "Bearer <REDACTED_REFRESH_TOKEN> -u <REDACTED_APP_KEY>:<REDACTED_APP_SECRET>". Expecting "Bearer <oauth2-access-token>".

 

pardon If my understanding is wrong , could you please guide me with the exact steps to be followed? 

I have taken the below reference to create dropbox client. instead of access token I have used refresh token as per your suggestion

GitHub - dropbox/dropbox-sdk-java: A Java library for the Dropbox Core API.

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

Hi again @Reshma ,

Seems you have misunderstood me. You can't just place one type of token where other type is expected! In Java SDK a DbxCredential object should be used as a proxy (don't ask me why) for refresh token.

Hope it's a bit more clear now.

Greg-DB
Dropbox Staff
Go to solution

@Reshma As Здравко indicated, you cannot use a refresh token as an access token. Refresh tokens and access tokens serve different purposes and are not interchangeable. You can find examples of using the authorization flow in the Java SDK here. You can find an example of using a credential with a client to make call here.

 

Also, for future reference, do not publicly post your refresh token or app secret. I've redacted them from your post. You may want to revoke it for the sake of security.

Reshma
Explorer | Level 3
Go to solution
Thanks. This helps.

Thang2000
Explorer | Level 4
Go to solution

the links are dead. Please update.

Greg-DB
Dropbox Staff
Go to solution

@Thang2000 Thanks for letting us know! I've updated the links in my previous post.

Need more support?