Learn how to make the most out of the Dropbox Community here 💙!

Forum Discussion

TimCadieux's avatar
TimCadieux
New member | Level 1
2 months ago

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.

About Discuss Dropbox Developer & API

Node avatar for Discuss Dropbox Developer & API
Make connections with other developers810 PostsLatest Activity: 4 days ago
232 Following

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!