cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more 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: 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

Leah C.1
New 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?

Peter M.107
New member | Level 1

Here's the code: https://github.com/p15martin/DropboxStream
I can re-create the issue consistently. Grab the token. Call https://api.dropbox.com/1/disable_access_token. Restart the app.

Leah C.1
New member | Level 1

Thanks for the code!

This is odd but I'm seeing nothing wrong. I'm able to link to Dropbox successfully. Here's the console output: https://www.dropbox.com/s/mttaf63iotmhan7/Screenshot%202015-06-17%2011.01.49.png?dl=0

Each time I re-open the app, everything works fine too: https://www.dropbox.com/s/zhvvoj39dup7z4z/Screenshot%202015-06-17%2011.02.11.png?dl=0

If I call /disable_access_token and re-open the app, I'm prompted to log in again, but then everything works as expected. Here's the console output:
Init dropbox
Has client
Token has expired
(note, at this point I'm prompted to re-auth)
Success! User is logged into Dropbox.
Reconnecting the account
Has client
Leah

I wonder if it's an issue with the Dropbox account that you're using to test the app. Are you testing the app with the same account you used to create the app in the Dropbox app console?

Peter M.107
New member | Level 1

In the code I shared I have a fix. In AppDelegate under Dropbox.handleRedirectURL(url), I am calling self.dropbox.verifyConnectionAfterAuth() which reconnects Dropbox.authorizedClient and DropboxClient.sharedClient. Try commenting it out and see if you get the problem.

Leah C.1
New member | Level 1

One thing you could do to improve this is in your AppDelegate's - application:openURL:sourceApplication:annotation: try using Dropbox.handleRedirectURL(url) instead of the lower-level method DropboxAuthManager.sharedAuthManager.handleRedirectURL(url). This will set the Dropbox.authorizedClient for you, so you don't need to do it yourself: https://github.com/dropbox/SwiftyDropbox/blob/master/Source/DropboxClient.swift#L67

The Dropbox class is really just a helpful wrapper around the DropboxAuthManager for the case where you only expect one account to be authorized at a time.

Peter M.107
New member | Level 1

That resolves the problem! Thanks!

Leah C.1
New member | Level 1

Oh good. Thanks so much for your feedback too!

Need more support?