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
Garnik G.
4 years agoExplorer | Level 4
DropBox API auth error - {".tag" = "expired_access_token"}
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 ma...
Garnik G.
Explorer | Level 4
Should I authorize the client everytime they hit dropbox button ?
So before I had this code
let dbClient = DropboxClientsManager.authorizedClient
if (dbClient != nil) {
// read files
} else {
//authorize
}
In some reason dbClient is always NOT nil even if I open the app after fresh uninstall.
So is there any specific attributes that I can use to check if user is already authorized or no ?
Greg-DB
4 years agoDropbox Staff
You do not need to send the user through the authorization flow every time they want to use the Dropbox integration. You can have them authorize it once, using authorizeFromControllerV2, and the SDK will automatically store the resulting access token and refresh token for you. You can use authorizedClient to check if you already have credentials saved for that user, and use it if so. The SDK will automatically perform the refresh process for you whenever needed.
Note though that the user or app can revoke the authorization at any time though, at which point you would need to have the user re-authorize the app if they wish to continue using the integration.
- Garnik G.4 years agoExplorer | Level 4
You did not answer to my question.
The problem is that DropboxClientsManager.authorizedClient is not nil all the time and I do not know how to check if user is authorized or not.
Please be specific.
- Greg-DB4 years agoDropbox Staff
That is how you check. You can check if authorizedClient is nil or not. If it is not nil, that means you have a saved client to use for that user. (And if the app was disconnected from the account server-side, attempting to use it will accordingly fail with an error.)
- Garnik G.4 years agoExplorer | 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?
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,910 PostsLatest Activity: 4 days agoIf 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!