cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Share your feedback on the Document Scanning Experience in the Dropbox App right here.

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: 

Token refreshing C#

Token refreshing C#

Melisek
Explorer | Level 3

I'm building an app in .net and accessing the app's folder for resources. So far everything is going smoothly, but i have no idea how to refresh the token in my app. I tried using the example code from OauthBasic from github, but i have a vague understanding of it and doesn't work for me. Would appreciate some help and guidance with it as i have no idea how to set it up. Thanks in advance.

35 Replies 35

Greg-DB
Dropbox Staff

@Melisek Thanks for pointing that out! I'll ask the team to fix that up.

Melisek
Explorer | Level 3

I'm trying to replace the spaces with + but it ignores it. Can't generate a refresh token with the scopes because of that.

RedirectUri.ToString().Replace(" ", "+")

Здравко
Legendary | Level 20

Easiest workaround would be proper quoting. :winking_face: (As would be on command line)

Melisek
Explorer | Level 3

You mean as a char? If yes then i tried that too.

Здравко
Legendary | Level 20

I mean something like:

"\"" + RedirectUri.ToString() + "\""

It works for me. :winking_face: In such a way the space char comes scopes separator only, but not arguments separator.

Melisek
Explorer | Level 3

 

Nvm i did it in the wrong line.

I replaced the chars in the redirectUri for the token result, not where i open the browser and pass in the url.

but now i get this:

Exception thrown: „Dropbox.Api.OAuth2Exception” in Dropbox.Api.dll
Exception thrown: „Dropbox.Api.OAuth2Exception” in System.Private.CoreLib.dll
invalid_grant: Error: {0}

Greg-DB
Dropbox Staff

@Melisek An 'invalid_grant' error typically indicates an misconfiguration of the parameters for the OAuth flow, such as an incorrect authorization code, mismatched redirect URI, etc. You should be able to get a more specific error message like this:

try
{
    // ... your ProcessCodeFlowAsync call ...

}
catch (OAuth2Exception ex)
{
// ...
	Console.WriteLine(ex.ErrorDescription);
// ...
}

Melisek
Explorer | Level 3

It prints out a redirect_uri mismatch

Greg-DB
Dropbox Staff

@Melisek That indicates that the redirect URI you're supplying when exchanging the authorization code doesn't match the one used to retrieve it originally. Make sure you're supplying the same redirectUri value to both GetAuthorizeUri and ProcessCodeFlowAsync.

Melisek
Explorer | Level 3

I had a mismatch of variables because of letter capitalization. Now i get the refresh token, acces token, uid, expiration date and the scopes returned, yet i still get the 400 Bad request error when calling client functions.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Melisek Explorer | Level 3
  • User avatar
    Здравко Legendary | Level 20
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?