You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
RJKinsman
6 years agoHelpful | Level 6
Getting "invalid_access_token" after getting DropboxClientsManager.authorizedClient
I'm doing something wrong in the Auth flow for my iOS app, but after looking at the photo watch sample app, I can't figure out where I'm going wrong. The problem is, I always get an invalid_access_to...
Greg-DB
Dropbox Staff
It looks like you're using the SwiftyDropbox SDK. You should save and re-use an access token once you get one, but the SDK does this for you automatically.
Can you confirm you configured your project and implemented the authorization flow exactly as documented? You didn't share your code for the "Handle redirect back into SDK" step in particular.
In any case, note that while access tokens currently don't expire on their own, they can be revoked by the app or user at any time. For that reason, you should make sure your app is able to catch an AuthError at any time. If the access token is invalid, you should throw it away and prompt the user to authorize your app again, if they still want to use the integration.
RJKinsman
6 years agoHelpful | Level 6
Thanks, Greg. I implemented the authorization flow as documented, to the best of my ability. Here is my application function where I handle the redirect back into the SDK:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { // Set up the viewcontroller variable var nvelopesViewController: UIViewController self.window = UIWindow(frame: UIScreen.main.bounds) let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) if let authResult = DropboxClientsManager.handleRedirectURL(url) { switch authResult { case .success(let token): print("Success! User is logged into Dropbox with token: \(token)") // Set the regular ViewController nvelopesViewController = mainStoryboard.instantiateViewController(withIdentifier: "sbNvelopes") as UIViewController // Display the selected View self.window?.rootViewController = nvelopesViewController self.window?.makeKeyAndVisible() case .cancel: print("Authorization flow was manually canceled by user!") case .error(_, let description): print("Error: \(description)") } } return true }
- RJKinsman6 years agoHelpful | Level 6
Also, here is my code in my ConnectToDropboxViewController where I begin the authorization flow:
@IBAction func connectToDropboxButtonTapped(_ sender: Any) { // Begin the Dropbopx authorization flow DropboxClientsManager.authorizeFromController(UIApplication.shared, controller: self, openURL: { (url: URL) -> Void in UIApplication.shared.open(url, options: [:], completionHandler: nil) })
- Greg-DB6 years agoDropbox Staff
Thanks! I don't see anything clearly wrong here.
It sounds like it's working now, but let me know if you are able to reproduce the issue again unexpectedly.
For reference, you should be able to intentionally cause that by e.g., unlinking the app, or deleting the app folder (if you're using an app with the app folder permission).
- RJKinsman6 years agoHelpful | Level 6
Great, thanks for the advice. Yes, working is a good thing.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,918 PostsLatest Activity: 2 days ago
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 or Facebook.
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!