Learn how to make the most out of the Dropbox Community here 💙!
Forum Discussion
TimCadieux
2 months agoNew member | Level 1
Using the DropBox API to host files for a public website (.net 9 Blazor)
My client has 100,000s of images stored in dropbox. The goal is to have some database information displayed alongside any one of the images.
From what I understand, I would need need to use a service account or OAuth2 so that the visiting user never knows anything about the file location and the only access is via the owners dropbox authority via the app.
I have tried to follow the online instructions but they are varied and change from site to site and over the years.
My first step was to load this url - https://www.dropbox.com/oauth2/authorize?client_id=&token_access_type=offline&response_type=code
This returned a Code. I placed this code the below .net 9 Blazor app but I cannot get past Bad Request
refreshToken = the code I got from the above?
public async Task<string> RefreshAccessTokenAsync(string refreshToken)
{
var client = _httpClientFactory.CreateClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.dropbox.com/oauth2/token")
{
Content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{ "grant_type", "refresh_token" },
{ "refresh_token", refreshToken },
{ "client_id", "xxxx" },
{ "client_secret", "xxxx" }
})
};
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync();
var tokenResponse = JsonSerializer.Deserialize<JsonElement>(json);
return tokenResponse.GetProperty("access_token").GetString();
}
Are there any step by step examples that work to do the above in 2025? I'm really banging my head against the wall here.
- DB-Des
Dropbox Engineer
Hi TimCadieux,
The code returned from the auth URL: https://www.dropbox.com/oauth2/authorize?client_id=&token_access_type=offline&response_type=code is an authorization code, not a refresh token.
To obtain a refresh token, you would first need to send a request to /oauth2/token with the value of the authorization code, from the first step. Below is the cURL equivalent for that request:
curl https://api.dropbox.com/oauth2/token \ -d code=<AUTHORIZATION_CODE> \ -d grant_type=authorization_code \ -d client_id=<APP_KEY> \ -d client_secret=<APP_SECRET>
The response from the above request will contain a refresh token value. You can then use that refresh token value to execute the code snippet you originally shared.
Feel free to reference our OAuth Guide and authorization documentation for any additional information.
About Discuss Dropbox Developer & API
Make connections with other developers810 PostsLatest Activity: 4 days ago
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 or Facebook.
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!