cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Tell us what you want to see on the Community here!
Close

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: 

DropBox API: uploading a file issue

Highlighted

DropBox API: uploading a file issue

Explorer | Level 3

Hello,

          I first get the token from:

 

https://api.dropbox.com/1/oauth2/authorize?response_type=code&client_idxxxxxxxxxx&redirect_uri=https...

 

          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

1 Reply 1
Highlighted

Re: DropBox API: uploading a file issue

Dropboxer

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.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?