cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you an educator? Well we want to hear from you, so check out some tools we think might help you out 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: 

SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

larschassing
Helpful | Level 6

Googling around led me to cocoadocs.org which seems to have an older version of SwiftyDropbox. It has createSharedLink(path:shortUrl:pendingUpload:)
"Create a shared link. If a shared link already exists for the given path, that link is returned."

which is exactly what I want.

http://cocoadocs.org/docsets/SwiftyDropbox/1.0/Classes/SharingRoutes.html#/s:FC13SwiftyDropbox13Shar...

 

However, now I can only find

createSharedLinkWithSettings(path: String, settings: Sharing.SharedLinkSettings? = nil)

that may return sharedLinkAlreadyExists, which isn't exactly useful.

OK, so the link already exists, but what IS the SharedLink url then ?

How do I find it ?

 

Why did you ditch the old pragmatic createSharedLink that simply returned the SharedLink url in any case ?

3 Accepted Solutions

Accepted Solutions

Re: SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

Greg-DB
Dropboxer

The official documentation for the sharing routes for the latest version of SwiftyDropbox can be found be found here.

 

The createSharedLink method was deprecated in favor of createSharedLinkWithSettings to match updates to the Dropbox product itself.

 

If a link already exists, you can retrieve it using listSharedLinks.

View solution in original post

Re: SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

Greg-DB
Dropboxer
I can't make any promises as to if or when that would be added, but I'm sending that along as a feature request.

View solution in original post

Re: SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

larschassing
Helpful | Level 6

When I looked closer at listSharedLinks I noted the path and directOnly arguments, that helped.

This is what I ended up with:

 

 

 

func OldCreateSharedLink(url: URL, dropboxPath: String, completionHandler: @escaping (_ sharedLink: String) -> Void) {
   if let client = DropboxClientsManager.authorizedClient {
      let request = client.sharing.createSharedLinkWithSettings(path: dropboxPath)
         .response { response, error in
            if let response = response {
               print(response)
               completionHandler(response.url)
            } else if let error = error {
               print(error)
               switch error as CallError {
               case .routeError(let boxed, let requestId):
                  print("RouteError[\(String(describing: requestId))]:")
                  switch boxed.unboxed as Sharing.CreateSharedLinkWithSettingsError {
                  case .sharedLinkAlreadyExists:
                     let request2 = client.sharing.listSharedLinks(path: dropboxPath, cursor: nil, directOnly: true)
                        .response { response, error in
                           if let response = response {
                              print(response)
                              if let theFirstTheBest = response.links.first {
                                 completionHandler(theFirstTheBest.url)
                              }
                           } else if let error = error {
                              print(error)
                           }
                     }
                     print(request2)
                  default:
                     print("\(boxed.unboxed)")
                  }
               default:
                  break
               }
            }
      }
      print(request)
   }
}

Thank you for your help

 

View solution in original post

4 Replies 4

Re: SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

Greg-DB
Dropboxer

The official documentation for the sharing routes for the latest version of SwiftyDropbox can be found be found here.

 

The createSharedLink method was deprecated in favor of createSharedLinkWithSettings to match updates to the Dropbox product itself.

 

If a link already exists, you can retrieve it using listSharedLinks.

View solution in original post

Re: SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

larschassing
Helpful | Level 6

Yes, I thought so, but then I need another round-trip and I have to parse the response searching for my file and bother with cursor...

 

Could you add a convenience method to work like the old createSharedLink, please ?

Re: SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

Greg-DB
Dropboxer
I can't make any promises as to if or when that would be added, but I'm sending that along as a feature request.

View solution in original post

Re: SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

larschassing
Helpful | Level 6

When I looked closer at listSharedLinks I noted the path and directOnly arguments, that helped.

This is what I ended up with:

 

 

 

func OldCreateSharedLink(url: URL, dropboxPath: String, completionHandler: @escaping (_ sharedLink: String) -> Void) {
   if let client = DropboxClientsManager.authorizedClient {
      let request = client.sharing.createSharedLinkWithSettings(path: dropboxPath)
         .response { response, error in
            if let response = response {
               print(response)
               completionHandler(response.url)
            } else if let error = error {
               print(error)
               switch error as CallError {
               case .routeError(let boxed, let requestId):
                  print("RouteError[\(String(describing: requestId))]:")
                  switch boxed.unboxed as Sharing.CreateSharedLinkWithSettingsError {
                  case .sharedLinkAlreadyExists:
                     let request2 = client.sharing.listSharedLinks(path: dropboxPath, cursor: nil, directOnly: true)
                        .response { response, error in
                           if let response = response {
                              print(response)
                              if let theFirstTheBest = response.links.first {
                                 completionHandler(theFirstTheBest.url)
                              }
                           } else if let error = error {
                              print(error)
                           }
                     }
                     print(request2)
                  default:
                     print("\(boxed.unboxed)")
                  }
               default:
                  break
               }
            }
      }
      print(request)
   }
}

Thank you for your help

 

View solution in original post

Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    larschassing Helpful | Level 6
  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?