cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you interested in learning how media industry leaders use Dropbox Replay? Register for our webinar 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: 

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

ernstMreicher58
Super User

If your account-level is higher than basic then try a support ticket.

They should be able to help you faster.




Falls Ihnen meine Antwort gefallen oder geholfen hat, können Sie mir ein "Kudo" (Like) geben oder "Als Lösung akzeptieren" anklicken.
If you like my answer or find it helpful you could give me a "Kudo" (Like) or click at "Accept as Solution"

Garnik G.
Explorer | Level 4

Why dropbox become such an **bleep**?

 

Is there anybody from dropbox who can read this and try to help. 

 

I can't  find any way to contact them.

 

Maybe we should cancel the subscription.

 

Greg-DB
Dropbox Staff

The new short-lived access tokens used by the Dropbox API do expire after four hours, at which point you'd get this 'expired_access_token' error. In that case, you would either need to have the user re-authorize the app to get a new short-lived access token, or if the app requested "offline" access, use the refresh token to get a new short-lived access token programmatically. You can find more information on this in the OAuth Guide and this blog post.

 

You mentioned you're using Swift, but you didn't mention if you're using the official SwiftyDropbox SDK. If you are using that SDK, it should do all of this work for you, including setting up and using "offline" access, as long as you're using a recent version of it and set it up as documented (i.e., using authorizeFromControllerV2).

 

If something's not working as expected, I'll be happy to help, but I'll need some more information. In that case, please reply with:

  • the name and version number of the platform and SDK/library you are using, if any
  • the steps to reproduce the issue, including relevant code snippet(s), but don't include any access/refresh token(s)

Garnik G.
Explorer | Level 4

I use SwiftyDropBox which was install by pod

 

The version number is 7.0.1

 

Please note this code was working fine before.

 

I do not use any access_token 

 

What I use is this 

 

DropboxClientsManager.setupWithAppKey("<my key>")

 

And this is the function I call when user click to dropbox button

 

   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

            DropboxClientsManager.authorizeFromController(UIApplication.shared,

                                                          controller: self,

                                                          openURL: { (url: URL) -> Void in

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

            })

        }

    }

 

Greg-DB
Dropbox Staff

Thanks for the additional information. From this I see you're using the 'authorizeFromController' method. You'll need to switch to using the 'authorizeFromControllerV2' method instead as shown here to support the new flow. Once you do so, the SDK will automatically handle short-lived access tokens and refresh tokens for you so you shouldn't receive 'expired_access_token' for new authorizations.

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
Dropbox 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.
Explorer | 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-DB
Dropbox 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.)

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Garnik G. Explorer | Level 4
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?