Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
Hello,
I first get the token from:
following https://www.dropbox.com/developers/documentation/dotnet#tutorial
I use the following method: https://dropbox.github.io/dropbox-sdk-dotnet/html/M_Dropbox_Api_Files_Routes_FilesUserRoutes_UploadA...
using (var dbx = new DropboxClient(token))
I call the following method:
async Task Upload(DropboxClient dbx, string folder, string file, string content)
{
using (var mem = new MemoryStream(Encoding.UTF8.GetBytes(content)))
{
var updated = await dbx.Files.UploadAsync(
"/" + file,
WriteMode.Overwrite.Instance,
body: mem);
}
}
I get the following error when trying to upload (dbx.Files.UploadAsync) : Dropbox.Api.AuthException: invalid_access_token
I use the token right after accessing the oauth2 page with credentials and it returns a token.
Could you please advise as what is the problem with the invalid token error?
Thank you
In your /oauth2/authorize URL, I see that you're using the 'response_type=code' flow, which means you're using the OAuth 2 "code flow". In this flow, the code that you get back from that page is an "authorization code", not an "access token". When using the code flow, you need to then exchange the authorization code for an access token by calling /oauth2/token. The /oauth2/token response will contain the access token that you can then use to make actual API calls. (Attempting to use an authorization code in place of an access token to attempt to make actual API calls will result in an 'invalid_access_token' error.) You can find more information on how the OAuth flow works in the OAuth Guide, as well as the authorization documentation.
And if you're using the official Dropbox .NET SDK anyway, you should use the OAuth helpers it provides, as that will do much of the work for you. The documentation includes examples of how to use those in different contexts, resulting in an access token. There's also a sample web app that implements the OAuth flow as an example.
Also, note that per the documentation, the app authorization page should be accessed at https://www.dropbox.com/oauth2/authorize , not on api.dropbox.com as you have in your post.
Hi there!
If you need more help you can view your support options (expected response time for a 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!