cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you using the Microsoft co-authoring beta for Dropbox? Share your feedback and learn more about it 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: 

SwiftyDropbox (v0.2) - invalid_access_token

SwiftyDropbox (v0.2) - invalid_access_token

Peter M.107
New member | Level 1

Hi,

I'm trying out SwiftyDropbox and following the code given in the blogpost (https://blogs.dropbox.com/developers/2015/05/try-out-swiftydropbox-the-new-swift-sdk-for-dropbox-api...).

When I try and do something (e.g. client.usersGetCurrentAccount()) I get an HTTP error: invalid_access_token

Any help would be appreciated.

-Peter

16 Replies 16

Rich
Super User II

Moved to API forum.

Leah C.1
New member | Level 1

Are you sure the user has completed the auth flow? Maybe check that you have a valid access token with DropboxAuthManager.sharedAuthManager.hasStoredAccessTokens() or by printing DropboxAuthManager.sharedAuthManager.getAllAccessTokens()?

Peter M.107
New member | Level 1

Thanks Leah. Yes the user has completed the auth flow.
DropboxAuthManager.sharedAuthManager.hasStoredAccessTokens() is true
And DropboxAuthManager.sharedAuthManager.getAllAccessTokens() contains my token.

Leah C.1
New member | Level 1

Hmmm... this could also happen if the access token has been revoked. Maybe try Dropbox.unlinkClient() and re-authorizing?

Peter M.107
New member | Level 1

That worked. Is there any way to guard/check for a revoked token?

Leah C.1
New member | Level 1

There's no way to know if a token has been revoked until you make an API call. You'll need to look for a 401 error response and then call Dropbox.unlinkClient() to clear the bad tokens.

Peter M.107
New member | Level 1

Hi Leah,
I am just following up on this again as I've had a couple of issues along the way. The main issue I've had is not being able to call Dropbox after auth. It happens if it's the first time I auth or if I call Dropbox.unlinkClient() then re-auth. The problem seems to be the same - Dropbox.authorizedClient and DropboxClient.sharedClient are nil.
I also didn't like that the 401 was embedded in the error string. I added an extension to make the http code more easily accessible and to handle the unlinking. I've ended up wrapping SwiftyDropbox (https://gist.github.com/p15martin/82cbae8188729f26fbbb).
Interested in your thoughts?
-Peter

Leah C.1
New member | Level 1

Just to clarify, Dropbox a user is authorized by clicking a link in your app which calls Dropbox.authorizeFromController(controller). This presents a web view for the user to login and afterwards, you're calling Dropbox.handleRedirectURL(url) which handles storing the access token for the user. There's no need to set or get access tokens manually - just be sure to call Dropbox.handleRedirectURL(url) in your AppDelegate's
- application:openURL:sourceApplication:annotation:
method (this isn't shown in your gist but I'm assuming you're doing this??). Does that help clear things up?

I'll pass along the feedback about the error object to the team. Thanks!

Peter M.107
New member | Level 1

Thanks. Yes I am calling Dropbox.handleRedirectURL(url) in my app delegate.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Leah C.1 New member | Level 1
  • User avatar
    Peter M.107 New member | Level 1
What do Dropbox user levels mean?