Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
Peter M.107
10 years agoNew member | Level 1
SwiftyDropbox (v0.2) - invalid_access_token
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-v2/).
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
Replies have been turned off for this discussion
- Rich10 years ago
Super User II
Moved to API forum.
- Leah C.110 years agoNew 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 printingDropboxAuthManager.sharedAuthManager.getAllAccessTokens()? - Peter M.10710 years agoNew 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.110 years agoNew member | Level 1
Hmmm... this could also happen if the access token has been revoked. Maybe try
Dropbox.unlinkClient()and re-authorizing? - Peter M.10710 years agoNew member | Level 1
That worked. Is there any way to guard/check for a revoked token?
- Leah C.110 years agoNew 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.10710 years agoNew 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 callDropbox.unlinkClient()then re-auth. The problem seems to be the same -Dropbox.authorizedClientandDropboxClient.sharedClientarenil.
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.110 years agoNew 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 callingDropbox.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 callDropbox.handleRedirectURL(url)in your AppDelegate'smethod (this isn't shown in your gist but I'm assuming you're doing this??). Does that help clear things up?
- application:openURL:sourceApplication:annotation:I'll pass along the feedback about the error object to the team. Thanks!
- Peter M.10710 years agoNew member | Level 1
Thanks. Yes I am calling
Dropbox.handleRedirectURL(url)in my app delegate. - Leah C.110 years agoNew member | Level 1
Could you also include the code from the view controller where you're calling the DropboxAPI methods? Maybe also include your AppDelegate code? I tested the code from the blog post this morning and it appears to be working okay. Are you doing anything differently for your app?
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
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, Facebook or Instagram.
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!