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

Здравко
Legendary | Level 20

@Melisek,

Name all your vars properly to avoid confusion! For instance, is 'RedirectUri' really means redirect URI or ... something else? :winking_face:

Melisek
Explorer | Level 3

I copied the code from the repo. 

They are named almost the same

and they will be temporary as i don't need oauth on users for my app.

 

private static readonly Uri RedirectUri = new Uri(LoopbackHost + "authorize");
var redirectUri = await HandleJSRedirect(http);

 

 

Greg-DB
Dropbox Staff

@Melisek For the 400 error, please share the full error message as well as the relevant code snippet.

Melisek
Explorer | Level 3

I'm catching an HttpRequestException using this

 

catch(HttpRequestException ex)
{
    Debug.WriteLine(ex.ToString());
}

 

trying to get acces using this

private async Task<List<string>> GetUpdateList(string dirPath)
        {
            List<string> list = new List<string>();
            var files = await dbx.Files.ListFolderAsync(dirPath);
            fileNames.Clear();

            foreach (var item in files.Entries.Where(i => i.IsFile))
            {
                fileNames.Add(item.Name);
                list.Add(item.Name[..^4]);
            }

            return list;
        }

 

 

And it logs

System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at Dropbox.Api.DropboxRequestHandler.RefreshAccessToken(String[] scopeList)
at Dropbox.Api.DropboxRequestHandler.CheckAndRefreshAccessToken()
at Dropbox.Api.DropboxRequestHandler.RequestJsonStringWithRetry(String host, String routeName, String auth, RouteStyle routeStyle, String requestArg, Stream body)
at Dropbox.Api.DropboxRequestHandler.Dropbox.Api.Stone.ITransport.SendRpcRequestAsync[TRequest,TResponse,TError](TRequest request, String host, String route, String auth, IEncoder`1 requestEncoder, IDecoder`1 responseDecoder, IDecoder`1 errorDecoder)
at MelisekGameManager.RWindow.GetUpdateList(String dirPath) in C:\Programming\C#\MelisekGameManager\MelisekGameManager\RWindow.cs:line 167
at MelisekGameManager.RWindow.gameSelect_SelectionChangeCommitted(Object sender, EventArgs e) in C:\Programming\C#\MelisekGameManager\MelisekGameManager\RWindow.cs:line 231

 

Здравко
Legendary | Level 20

'dbx' object seems not properly initialized.

Take a look how have you initialized it.

Melisek
Explorer | Level 3

Yep, i was setting a different refresh token after i requested one from the api. Now everything works perfectly! Thanks for your time.

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?