You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

Omri1984's avatar
Omri1984
Explorer | Level 4
3 years ago

Access token not beeing refreshed automatically

my application support old dropbox and the new one.

when creating the client i am creating it like this


client = new DropboxTeamClient(request.AccessToken, request.RefreshToken,request.Expires,ClientId,ClientSecret);

and then using it 

in this way 

first Way

var members = await client.Team.MembersListAsync().ConfigureAwait(false);

 

and this way 

Second Way

var account = await client.AsMember(request.AsMember).Users.GetCurrentAccountAsync();
var clientNew= client.AsMember(request.AsMember).WithPathRoot(new PathRoot.Root(account.RootInfo.RootNamespaceId));

var folders = await spaceclient.Files.ListFolderAsync(folderId);

 

 

my issue is after 4 hours when the token is expired 

When i calling the  first way i am getting an error 

Response status code does not indicate success: 400 (Bad Request).

 

at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at Dropbox.Api.DropboxRequestHandler.<RefreshAccessToken>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Dropbox.Api.DropboxRequestHandler.<CheckAndRefreshAccessToken>d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Dropbox.Api.DropboxRequestHandler.<RequestJsonStringWithRetry>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Dropbox.Api.DropboxRequestHandler.<Dropbox-Api-Stone-ITransport-SendRpcRequestAsync>d__12`3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at MaaS.Systems.Dropbox.Service.DropboxService.<GetUsersAsync>d__26.MoveNext() in C:\development\CloudSfer\Systems\MaaS.Systems.Dropbox\Service\DropboxService.cs:line 157
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at MaaS.Systems.Dropbox.DropboxServiceExtender.<GetHierarchy>d__7.MoveNext() in C:\development\CloudSfer\Systems\MaaS.Systems.Dropbox\DropboxServiceExtender.cs:line 126
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at MaaS.Web.Controllers.Api.DropboxController.<TreeViewNodes>d__7.MoveNext() in C:\development\CloudSfer\MaaS.Web\Controllers\Api\DropboxController.cs:line 175

 

 

it is look like it is failing on refreshing token .

 

the problem is that this request is not exist in the new client 

Team.MembersListAsync(). not exist in the new client

 

 

please advice 🙂

 

Any Update Please 

maybe this method client.Team.MembersListAsync() not handling as it should with the refresh token 

 

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    The first way looks correct, and that code is working for me when I supply valid credentials. Make sure you're supplying the correct and valid values. For example, make sure:

    • the refresh token is exactly as originally provided by Dropbox
    • the refresh token hasn't been revoked by the app or user
    • the client ID and secret, a.k.a., app key and secret, are exactly as originally provided by Dropbox
    • the client ID and secret, a.k.a., app key and secret, are for the same app as the refresh token

     

    For the second way, it is expected that "clientNew" would not have the MembersListAsync method, since the MembersListAsync method is only available on DropboxTeamClient instances, not DropboxClient instances. The AsMember method returns a DropboxClient instance to operate on a specific member, not the whole team. The WithPathRoot method sets the root for the files calls made by the client. Neither of these control the refresh process.

    • Omri1984's avatar
      Omri1984
      Explorer | Level 4

      ok, but if i am calling the first way 

      i am getting the error.

       

      I am trying to understand.

      after 4 hours i am creating the dropbox team client with all the correct data(access,refresh,secret etc..).

      but getting an error 

      can you try and reproduce it .

      create a new token with 4 hours.

      then wait 4 hours and then call the new dropbox team client with the token then you get before and call the client.Team.MembersListAsync()

      i even try to call the refresh token method manually  but this didn't work also 

       

       

      need your help 🙂

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        Yes, I tried the code you shared, plugging in valid refresh token, etc. values, and it worked for me.

         

        Please review the list in my previous message for reasons why that would fail for you. Check and update your values as necessary to make sure you're providing correct and valid refresh token, etc. credentials.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,910 PostsLatest Activity: 3 days ago
333 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!