cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: 

Generating Refresh Token using example code

Generating Refresh Token using example code

lsteel11
Explorer | Level 4

Hi, 

 

I am trying to generate a refresh token following the example code (https://github.com/dropbox/dropbox-sdk-python/blob/main/example/oauth/commandline-oauth-pkce.py) (but with my app key etc). 

 

I am able to successfully implement it up until line 19. When I run the next section python just shuts down. Any help would be much appreciated! Thank you! 

 

Laura 

7 Replies 7

Greg-DB
Dropbox Staff

Can you elaborate on what you mean when you say "python just shuts down"? Is there any error/output?

 

After line 19, you should either get an error printed via line 22, or execution should continue and perform the users_get_current_account call (though this minimal example doesn't actually do anything with the result) and then print "Successfully set up client!".

lsteel11
Explorer | Level 4

Hi Greg, 

 

Thanks for your response. I have taken a screenshot (below). When I click return at this point (so that I can then run the next section of code) the python window closes immediately. I presume this is something to do with the exit(1) command? Many thanks. 

 

python..png

 

 

Greg-DB
Dropbox Staff

It looks like you're running your python3.10.exe directly, and the window is closing automatically when the program completes (such as from the exit call, as you mentioned). I can't really offer support for your development environment itself as that's not made by Dropbox, but there are other ways to set this up so that you get to see the output even once execution completes, e.g., you may want to save the code as a file and run that from the command line.

lsteel11
Explorer | Level 4

Hi Greg, 

 

I see! I have now run the file from the command line and output "successfully set up client!"

 

What is the next step to actually generating a refresh token? 

 

Many thanks, 

Laura 

Greg-DB
Dropbox Staff

If you've reached "Successfully set up client!" in that sample, you've already successfully processed the app authorization flow and retrieved a refresh token. The refresh token is in 'oauth_result.refresh_token' in that sample, e.g., as used in line 25. For your actual app, you can store and re-use that.

lsteel11
Explorer | Level 4

Hi Greg, 

 

Sorry - still having trouble. I have retrieved (what I think is) the refresh token - I added "print (oauth_result.refresh_token) to the end of the script and ran it from the command line etc, and it output what looked like a token. 

 

However, when I put this token in the NodeRed dropbox node, it says that the access token is invalid. 

 

If you had any further thoughts on this it would be much appreciated. Thank you. 

Greg-DB
Dropbox Staff

Refresh tokens and access tokens are not interchangeable. Refresh tokens cannot be used as access tokens. Refresh tokens are instead used to programmatically retrieve new short-lived access tokens whenever needed (without manual user interaction).

 

The official Dropbox SDKs will do that for you automatically, e.g., if you create the client as shown in line 25 of the example.

 

I can't provide support for "the NodeRed dropbox node" as that's not made by Dropbox though, so you may need to refer to the documentation or support resources for that for information on configuring that.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    lsteel11 Explorer | Level 4
What do Dropbox user levels mean?