cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: 

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

Greg-DB
Dropbox 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
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
Dropbox 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.

Omri1984
Explorer | Level 4

i an not understand and will need more assistance.

 

in my up i am always using the DropboxTeamClient creating it with all the necessary parameters

like this.

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

 

now after that i am checking if the client is in the new space or the old one 

 

like this 

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)
{

metadata = await spaceclient.Files.ListFolderAsync(folderId);
}
else
{
metadata = await client.AsMember(request.AsMember).Files.ListFolderAsync(folderId)
}

 

now sometimes i need to call this 

client.Team.MembersListAsync().ConfigureAwait(false);

 

 

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 

 

 

and my issue is that after the token is expire i am getting the error that was in the first message .

400 error 

 

i am really need to get to the bottom  of this and understand is completely 

Thank you 

Здравко
Legendary | Level 20

Hi @Omri1984,

Can you just print (or display somehow) content of "request.RefreshToken"? Is there something that looks like valid refresh token or not exactly? 🧐

Hope this gives direction.

Omri1984
Explorer | Level 4

something like this 

ZEaFs***lgUAAAAAAAAAARUCp-9WwOK************************PIUr3P72**********Eg

 

does it make sense ?

Здравко
Legendary | Level 20

Hi again @Omri1984,

To be honest I expected your token empty, but it seems Ok, at least. Let's see is it really Ok or not actually. Execute following command in terminal:

curl https://api.dropbox.com/oauth2/token -d grant_type=refresh_token -d refresh_token=ZEaFs***lgUAAAAAAAAAARUCp-9WwOK************************PIUr3P72**********Eg -u 12APP_KEY3HERE45:abcAPP_SECRETdHEREefg

Place actual values on their corresponding places. You can use other standalone HTTP client, able to perform such a request, if curl is missing or inconvenient for your. Does the command completes successfully or gives back error (if error, what kind of error - post the result)?

Omri1984
Explorer | Level 4

will test it, 

if i am asing a token with the business app or with the user app does the token is different between ?

Здравко
Legendary | Level 20

The token itself (both refresh and access) no (the above call is NOT affected). You have to take this in mind when actual API calls are performed (adding additional headers, whenever and if needed, on business account - as you are doing). That's it.

Need more support?
Who's talking

Top contributors to this post

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