Forum Discussion

Gonzo345's avatar
Gonzo345
Helpful | Level 5
9 years ago
Solved

Getting the shared link using the deprecated GetSharedLinksAsync(path)

Hi there!

 

I'm facing problems retrieving a shared link which is already created. I'm basically trying to "create" the Shared Link every time I upload a file and storing that URL on a DB but I'm stuck on the "shared_link_aready_exists" part.

 

I'm using the .NET API and I tried to use the

DropboxClient.Sharing.CreateSharedLinkWithSettingsAsync(remotePath);

but even if the file is being overwritten, if it already has a Shared Link created, it will give the "shared_link_already_exists" return, stopping there.

 

I've been taking a look at the API and looks like

DropboxClient.Sharing.GetSharedLinksAsync(remotePath)

is my method, but it only works if the link is already created. And poorly, this method is deprecated, so it will surely stop working anytime...

 

I guess there is a way to control that but I'm in a point that I don't move forward. Could anybody help me? Many thanks.

  • If a shared link already exists for a file or folder, you can use ListSharedLinksAsync with path as the path to the desired file or folder and directOnly=true to get the existing link.

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

    If a shared link already exists for a file or folder, you can use ListSharedLinksAsync with path as the path to the desired file or folder and directOnly=true to get the existing link.

    • Gonzo345's avatar
      Gonzo345
      Helpful | Level 5

      Hi again, Greg the Dropmaster! Thank you so much, I finally did it this way, so I control if the link is already created and act if so :slight_smile:

       

       var link = await dbx.Sharing.ListSharedLinksAsync(remoteFilePath);
       if(link.Links.Count == 0)
       {
      var result = await dbx.Sharing.CreateSharedLinkWithSettingsAsync(remoteFilePath); string url = result.Url; Console.WriteLine("The url for sharing " + remoteFilePath + " is: " + url); } else { string url = link.Links[0].Url; Console.WriteLine("(ALREADY GENERATED) The url for sharing " + remoteFilePath + " is: " + url); }

       

      You made my friday, Greg! :sunglasses: 

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,950 PostsLatest Activity: 2 hours ago
352 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!