cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

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
Highlighted

Re: SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

Dropboxer
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

Highlighted

Re: SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

Dropboxer
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

Highlighted

Re: SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

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
Highlighted

Re: SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

Dropboxer
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

Highlighted

Re: SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

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 ?

Highlighted

Re: SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

Dropboxer
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

Highlighted

Re: SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

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

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?