cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Share your feedback on the Document Scanning Experience in the Dropbox App right 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: Tokens only valid for 4 hours from app console

Re: Tokens only valid for 4 hours from app console

gcarl
Explorer | Level 4

Dear greg-DB,

 

sorry, but I have to come back to this topic again, since I couldn't solve it in the recent weeks despite all these valuable hints in this forum and the description for the Swift SDK.

 

I'm writing an app with Swift and I originally set it up with a long-term token, which was changed by Dropbox in the meantime.

 

I do the setup in the appDelegate with (dropboxAppKey is the key I created  in the Dropbox-portal for my App)

 

 

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        UIApplication.shared.registerForRemoteNotifications()
        DropboxClientsManager.setupWithAppKey(dropboxAppKey) 
...
}

 

 

 

and I'm doing the connect as decribed with 

 

 

func connectDropbox() {
        let scopeRequest = ScopeRequest(scopeType: .user, scopes: ["files.content.write", "files.content.read", "account_info.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 as described in appDelegate with:

 

 

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        let oauthCompletion: DropboxOAuthCompletion = {
          if let authResult = $0 {
              switch authResult {
              case .success:
                  print("Success! User is logged into DropboxClientsManager.")
              case .cancel:
                  print("Authorization flow was manually canceled by user!")
              case .error(_, let description):
                  print("Error: \(String(describing: description))")
              }
          }
        }
        let canHandleUrl = DropboxClientsManager.handleRedirectURL(url, completion: oauthCompletion)
        return canHandleUrl
    }

 

 respectively as described in the SDK for the SceneDelegate.

 

Everything works fine and I can access data from and save data to the Dropbox for a certain while (it seems to be even less than 4 hours) and then out of a sudden the connection is interrupted. 

 

Within my app I check the availability of the dropbox before saving or retrieving data with:

 

if let client = DropboxClientsManager.authorizedClient {
                         dropboxClient = client
                         dropboxClient!.files.download(path: ... )
                             .response { response, error in
                                 if let response = response {
                                     let _ = response.0
                                     let fileContents = response.1
                                     <code>
                                 } else if let error = error {
                                     switch error as CallError {
                                     case .routeError:
                                        <code>
                                     default:
                                        <code>
                                         return
                                     }
                                 }
                             }
                     }

 

 

Unfortunately, I can't manage the described automatic refresh for my app. Is there a certain coding I have to call if the above mentioned availability-check ("if let client = DropboxClientsManager.authorizedClient ") provides nil?

 

Thanks for your support

11 Replies 11

gcarl
Explorer | Level 4

Dear Greg-DB,

 

I tested your test app on different devices and it worked as expected without any problems.

Since the code of your test app is exactly the same I use in my apps except for the Dropbox appkey, the questions is, if the problems are linked with the appkey? I originally registered the apps with a long term token, which was changed automatically meanwhile in course of your initiative of replacing these tokens.

 

Kind regards gcarl

Greg-DB
Dropbox Staff

There shouldn't be anything unusual about your app key in particular. To check that though, you could try replacing my app key in the sample project with yours and retesting it. Please try that and let me know how it goes.

Need more support?
Who's talking

Top contributors to this post

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