We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
AG15
4 years agoExplorer | Level 4
Refresh Tokens
Hello, I've been reading dozens of pages of documentation, blogs, dropbox forum posts and other information without avail. Most of the API is pretty straighforward and easy to use but I'm hitting a r...
Greg-DB
Dropbox Community Moderator
4 years agoTo get a refresh token, you'll need to use the OAuth app authorization flow. It is possible to process this in C#. For the official Dropbox API v2 .NET SDK in C#, you can find an example of getting and using a refresh token in the OauthBasic example (non-PKCE, meant for server-side apps) as well as in the OAuthPKCE example (PKCE, meant for client-side apps).
If this is just for your own use though, that is, you only need to connect your own account, you don't really need to implement that in C#. You can process this manually once and copy/paste the necessary values, which would likely be easier.
For instance, you could:
- Make your OAuth app authorization URL like this: https://www.dropbox.com/oauth2/authorize?client_id=APPKEYHERE&response_type=code&token_access_type=offline (plug in your app key in place of "APPKEYHERE").
- Browse to that page in your browser while signed in to your account and click "Allow" to authorize it.
- Copy the resulting authorization code.
- Exchange the authorization code for an access token and refresh token like this, e.g., using curl on the command line: (plug in the authorization code from step 3 in place of "AUTHORIZATIONCODEHERE," the app key in place of "APPKEYHERE", and the the app secret in place of "APPSECRETHERE").
curl https://api.dropbox.com/oauth2/token \ -d code=AUTHORIZATIONCODEHERE \ -d grant_type=authorization_code \ -u APPKEYHERE:APPSECRETHERE
The response will contain a short-lived access token and refresh token that you can then plug in to your code as needed.
AG15
4 years agoExplorer | Level 4
Thanks the reply Greg.
These are the specific steps I took to get my refresh token (written in a guide format)
- Register your app and get your <App Key> and <App Secret> from the App dashboard
- Add a localhost <Redirect URI> in the App dashboard’s Redirect URL section
- Insert your app key and the redirect URL you set in #2 in the following URL: https://www.dropbox.com/oauth2/authorize?client_id=<APP KEY>&redirect_uri=<YOUR_REDIRECT_URI>&response_type=code&token_access_type=offline
- For me, I just ran a local host server in Visual Studio with an endpoint for the redirect URL so I could catch it to examine the redirect URL.
- Copy and paste the URL from #3 into your browser, follow the steps on dropbox’s page and it will hit your redirect URL with an <AUTHORIZATION CODE> attached to the redirect URL
- Download CURL for windows (if you’re a Windows user)
- Open a command window in the CURL directory and type in the following: curl https://www.dropbox.com /oauth2/token –d code=<AUTHORIZATION CODE> -d grant_type=authorization_code -d redirect_uri=<REDIRECT_URI> -u <APP KEY>:<APP SECRET>
- This will return a json payload, get the refresh token from it and use it with your App Key and App Secret as parameters for the DropboxClient constructor. The Dropbox API will handle getting short-lived tokens each time it’s used. Your refresh token won’t expire.
About Discuss Dropbox Developer & API
Make connections with other developers
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
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, Facebook or Instagram.
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!