cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
If you’ve changed your email address, now's the perfect time to update it on your Dropbox account and we’re here to help! Learn 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: DropBox API auth error - {".tag" = "expired_access_token"}

DropBox API auth error - {".tag" = "expired_access_token"}

Garnik G.
Explorer | Level 4

Language Swift

iOS Version 14.4

 

We have app where we use dropbox api to allow our users to upload a document.

 

This app used to working perfectly two years ago.

 

Very recently we made some small changes and trying to publish now.

 

DropBox API returns the following annoying error.

 

API Auth error - {".tag" = "expired_access_token";}

 

Please explain why in this version I am having this issue.

 

14 Replies 14

Garnik G.
Explorer | Level 4

Please let me know if I miss anything from the following

 

1. I remove the app completely from simulator or device

 

2. I disconnec the dropbox app from my dropbox account

 

3. I clean and rebuild the code.

 

4. I run the app and click to dropbox connect button the following function runs

 

func sendUsingDropBox() {

        

        let dbClient = DropboxClientsManager.authorizedClient

        

        if (dbClient != nil) {

            

            isDropBoxModalOpened = false

            startWI()

                        

            dbClient?.files.listFolder(path: "", recursive: true, includeMediaInfo: true).response(queue: DispatchQueue(label: "DbLfSerialQueue")) { response, error in

                if let result = response {

                    self.dbFolders.removeAll()

                    result.entries.forEach({(metdaData) in

                        if !metdaData.description.contains("size=") && !metdaData.description.contains("size =") {

                            self.dbFolders.append(metdaData.pathDisplay!)

                        }

                    })

                    DispatchQueue.main.async {

                        self.stopWI()

                        self.showChooser()

                    }

                } else if let error = error {

                    

                    print(error.description)

                    DispatchQueue.main.async {

                        self.stopWI()

                        let alert = UIAlertController(title: "DropBox", message: error.description, preferredStyle: UIAlertControllerStyle.alert)

                        alert.addAction(UIAlertAction(title: THAlerts.Ok, style: UIAlertActionStyle.default, handler: nil))

                        self.present(alert, animated: false, completion: nil)

                    }

                }

            }

 

        } else {

            

            isDropBoxModalOpened = true

            let scopeRequest = ScopeRequest(scopeType: .user, scopes: ["account_info.read", "files.content.write", "files.content.read", "files.metadata.write", "files.metadata.read"], includeGrantedScopes: false)

 

            DropboxClientsManager.authorizeFromControllerV2(UIApplication.shared, controller: self, loadingStatusDelegate: nil, openURL: { (url: URL) -> Void in

                UIApplication.shared.open(url, options: [:], completionHandler: nil)}, scopeRequest: scopeRequest)

            

        }

    }

 

And what happens is that  dbClient is not NULL and because of that it returns an error.

 

In my understanding dbClient must be NULL because everything was cleaned and removed.

 

What I miss here?

 

 

Greg-DB
Dropbox Staff

Even if you've uninstalled the app, the client may still be saved locally since that's persisted in the iOS keychain. And if you've disconnected the app via the Dropbox web site, the SDK won't yet know that the connection has been revoked on the server until you attempt an actual API call, like listFolder, at which point you'll get an authorization error.

 

You can just call authorizeFromControllerV2 again to prompt the user to re-authorize the app. Or, if you do want to explicitly remove the local client, you can call unlinkClients at any time.

Garnik G.
Explorer | Level 4

That is not a solution.

 

I can't write temporary code. I need to have normal way to verify if dbClient is valid object or not.

 

What if user want to connect another account.

 

There must be better approach.

 

 

Greg-DB
Dropbox Staff

I'm not sure understand what you mean what you mean by "temporary code". The authorization flow with authorizeFromControllerV2 works effectively the same as it did with authorizeFromController, since the SDK handles the refresh flow for you. Just like with authorizeFromController, you can just process the authorization flow with authorizeFromControllerV2 and let the SDK handle the access token details for you. You would check and use authorizedClient the same way in both cases. (While authorizeFromControllerV2 uses short-lived tokens in its implementation, it works the same way for the app's code as before, since it maintains long-term access using refresh tokens automatically just like the SDK previously maintained long-term access using long-lived access tokens from authorizeFromController.)

 

If you want to have the user switch to a different account, you can call authorizeFromControllerV2 again and it will replace the authorizedClient.

 

I recommend following the instructions in the current documentation. If something isn't working as expected/documented, please show both the steps/code you're using, as well as the full unexpected error/output.

Garnik G.
Explorer | Level 4

OK. I will try to see if it works also for other users. Thanks for help

 

 

 

Need more support?