We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

larschassing's avatar
larschassing
Helpful | Level 6
8 years ago

SwiftyDropbox createSharedLinkWithSettings (was createSharedLink)

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:FC13SwiftyDropbox13SharingRoutes16createSharedLinkFS0_FT4pathSS8shortUrlSb13pendingUploadGSqOCS_7Sharing17PendingUploadMode__GCS_15BabelRpcRequestCS1_26PathLinkMetadataSerializerCS1_31CreateSharedLinkErrorSerializer_

 

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 ?

  • 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.

  • Greg-DB's avatar
    Greg-DB
    8 years ago
    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.
  • 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

     

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    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's avatar
      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 ?

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff
        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.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,877 PostsLatest Activity: 12 months ago
325 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!