cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

larschassing
Helpful | Level 6
Go to solution

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

Greg-DB
Dropbox Staff
Go to solution

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

Greg-DB
Dropbox Staff
Go to solution
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

larschassing
Helpful | Level 6
Go to solution

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

Greg-DB
Dropbox Staff
Go to solution

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.

larschassing
Helpful | Level 6
Go to solution

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 ?

Greg-DB
Dropbox Staff
Go to solution
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.

larschassing
Helpful | Level 6
Go to solution

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

 

Need more support?