cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Great and all as it is to hear how we use Dropbox, we want to know how you use it! Day to day, big projects, sharing files with friends and family - we want to know about it.

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: 

Sign In via access token without login page

Sign In via access token without login page

Kirill
New member | Level 2

I created new account and uploaded some pictures. I also created Access Token. Users haven't dropbox account and I want to display these pictures in my application. Can I do this without login page?

It works good with login page:

DropboxClientsManager.authorizeFromController(UIApplication.shared,                                                      controller: self,                                                      openURL: { (url: URL) -> Void in
                                                      UIApplication.shared.openURL(url)
        })
let client = DropboxClientsManager.authorizedClient

 

But doesn't work with access token only:

let client = DropboxClient.init(accessToken: "...")

 

client?.files.download(path: "/pics")
            .response { response, error in
                if let response = response {
                    let responseMetadata = response.0
                    print(responseMetadata)
                    let fileContents = response.1
                    print(fileContents)
                } else if let error = error {
                    print(error)
                }
            }
            .progress { progressData in
                print(progressData)
        }

 

I got error: Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLKey=https://api-content.dropbox.com/2/files/download, NSErrorFailingURLStringKey=https://api-content.dropbox.com/2/files/download, NSLocalizedDescription=cancelled}

2 Replies 2

Re: Sign In via access token without login page

Greg-DB
Dropboxer

[Cross-linking for reference: https://stackoverflow.com/questions/42622883/swifty-dropbox-sign-in-via-access-token ]

 

The API was designed with the intention that each user would link their own Dropbox account, in order to interact with their own files. However, it is technically possible to connect to just one account. The SDKs don't offer explicit support for it and we don't recommend doing so, for various technical and security reasons.

 

However if you did want to go this route, instead of kicking off the authorization flow, you would manually use an existing access token for your account and app, as you're trying to here. (Just be careful not to revoke it, e.g. via https://www.dropbox.com/account/security .)

 

As far as the actual issue you're running in to, I suspect the issue is that you're constructing the client object and making the call, but then the client object is going out of scope before the response can come back. Make sure you keep your client object around. For example, you can use authorizedClient to store it, like this:

 

DropboxClientsManager.authorizedClient = DropboxClient.init(accessToken: "...")

 

And then use the client via DropboxClientsManager.authorizedClient.

Re: Sign In via access token without login page

TotteAlm
New member | Level 2

This one helped me a lot (my test code worked but when I moved it into the application, I trippde and fell like the OP. Thanks!

Who's talking

Top contributors to this post

  • User avatar
    TotteAlm New member | Level 2
  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?