cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We just wanted to say thank you! Check out our customer appreciation video 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: 

Re: Access token not beeing refreshed automatically

Access token not beeing refreshed automatically

Omri1984
Explorer | Level 4

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 

 

13 Replies 13

Здравко
Legendary | Level 20

@Omri1984 wrote:

...

and befoe every call i  am calling the 

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

 

and I need it because that sometimes i am handing for the same client al the data content and all the user and groups as well 

...


You don't need to do the above "before every call". Changing client representation is enough. Otherwise, you are slowing down your speed up to 2 times (on every regular API call one more refresh call). It's meaningless.

Greg-DB
Dropbox Staff

@Omri1984 It sounds like there's an issue with the credentials you're supplying, so trying the call outside of the SDK as Здравко suggested should be a useful test.

Omri1984
Explorer | Level 4

I added some logs to check my cred during the running .

I will update here, it holiday now so in a few days ,

thanks for the help.

 

by the way.

 

if create a new DropboxTeamClient(request.AccessToken, request.RefreshToken,request.Expires,ClientId,ClientSecret);

 

 

can I call those methods

 

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

if (account.RootInfo.IsTeam)
{
await spaceclient.Files.ListFolderAsync(folderId)

}

await client.Team.MembersListAsync()

 

await client.AsMember(request.AsMember).Files.ListFolderAsync(folderId)

 

 

and another question ,When using the .Net SDK when is the refresh token is happening?

does it happen for every method ?

does it happen when creating the client (new DropboxTeamClient(request.AccessToken, request.RefreshToken,request.Expires,ClientId,ClientSecret);)

 

Thank you 

Здравко
Legendary | Level 20

@Omri1984 wrote:

...

by the way.

 

if create a new DropboxTeamClient(request.AccessToken, request.RefreshToken,request.Expires,ClientId,ClientSecret);

 

 

can I call those methods

 

var account = await client.AsMember(request.AsMember).Users.GetCurrentAccountAsync();
...


Hi @Omri1984,

Overall idea is correct (only representation change 😉); you may need to check your syntax, etc in your end variant. Additional optimization can be done as "cache" your 'representation' , if in particular limited place multiple calls need to be performed sequentially (less objects construct/destruct -> will left one representation construct at beginning and one destruct at the end).

 


@Omri1984 wrote:

...

and another question ,When using the .Net SDK when is the refresh token is happening?

does it happen for every method ?

...


Yes and No. On every method call, SDK (all of them - not only .Net) check if current access token exists and its validity. That's what's done mandatory. If there is not available access token or it's going to expire (or already expired), refresh gets performed (which means once on every 4 hours roughly, if you use your code continuously).

 


@Omri1984 wrote:

...

does it happen when creating the client (new DropboxTeamClient(request.AccessToken, request.RefreshToken,request.Expires,ClientId,ClientSecret);)

 ...


No, it doesn't happen on client object creation time, but on methods execution (as I mentioned above). Warning: on client object creation, the state is reset, which means almost mandatory first call will need to refresh the token! As mentioned something meaningless. That's why it's not good idea to create client object continuously for every call, cosa the call gonna be forced to refresh (not the object construction itself). ".Net" SDK implementation doesn't provide currently some way to keep current state (like Java SDK or Python SDK). That's why the last state can't be restored (without some hacks/patches). Seems like a design bug. Let's hope this bug will be fixed.

Hope it's a bit more clear now.

Need more support?