cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We want your feedback when it comes to using Dropbox in a web browser. Tell us your thoughts right 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: 
1
Ask
2
Comments

Re: Dropbox API .NET SDK: Modifying shared link password issues.

Dropbox API .NET SDK: Modifying shared link password issues.

AGreenTejada
Helpful | Level 5

Hello everyone,

 

Seems that there's an issue in the SDK with modifying shared link settings. I am using Dropbox.Api Nuget V6.13.0. with an Admin-accessed internal app. I am able to set up passwords on client folders, but I am unable to remove passwords on those folders through the API. To expand, the SetLinkPassword() method successfully processes and changes the link status to password. However, the RemoveLinkPassword() method successfully process, but does not remove the password.

 

Here's the code in C#.

 

// This is the NUnit test. client.DropboxSharedURL is the URL to the client's folder, which they have View access to.

[Fact]
        public async Task SetSamplePassword()
        {
            var clients = Clients.Read();
            var client = clients[1000];
            string password = "testpassword";

            await Password.SetLinkPassword(client.DropboxSharedURL, password);
            Assert.Equal(true, await Password.HasPassword(client.DropboxSharedURL));

            await Password.RemoveLinkPassword(client.DropboxSharedURL);
            Assert.Equal(false, await Password.HasPassword(client.DropboxSharedURL));

        }
 //These are the two methods I am using to set/reset the Link password.

public static async Task SetLinkPassword(string url, string password)
        {
            var accesslevel = new RequestedLinkAccessLevel().AsViewer;
            var audience = new LinkAudience().AsPassword;
            var sharedlinksettings = new SharedLinkSettings(true, password, null, audience, accesslevel, null, true);

            await user.Sharing.ModifySharedLinkSettingsAsync(url, sharedlinksettings, false);
        }

public static async Task RemoveLinkPassword(string url)
        {
            var accesslevel = new RequestedLinkAccessLevel().AsViewer;
            var audience = new LinkAudience().AsPublic;
            var visibility = new RequestedVisibility().AsPublic;
            var sharedlinksettings = new SharedLinkSettings(false, null, null, audience, accesslevel, visibility);

            await user.Sharing.ModifySharedLinkSettingsAsync(url, sharedlinksettings, false);
        }
//This checks if a link has a password.
public static async Task<bool?> HasPassword(string url)
        {
            try
            {
                var metadata = await user.Sharing.GetSharedLinkMetadataAsync(url);
                return metadata.LinkPermissions.RequestedVisibility.IsPassword;
            }
            catch
            {
                return null;
            }

        }

 

 

1 Accepted Solution

Accepted Solutions

Re: Dropbox API .NET SDK: Modifying shared link password issues.

Greg-DB
Dropboxer

When setting options like this, you should use the provided instance, like this:

var visibility = RequestedVisibility.Public.Instance;

 

Also, I see you're checking the "RequestedVisibility" in the result, but you probably want to actually check "ResolvedVisibility", since that's what tells you what the final state actually is (e.g., once team policies were taken into account as well).

View solution in original post

2 Replies 2

Re: Dropbox API .NET SDK: Modifying shared link password issues.

Greg-DB
Dropboxer

When setting options like this, you should use the provided instance, like this:

var visibility = RequestedVisibility.Public.Instance;

 

Also, I see you're checking the "RequestedVisibility" in the result, but you probably want to actually check "ResolvedVisibility", since that's what tells you what the final state actually is (e.g., once team policies were taken into account as well).

Re: Dropbox API .NET SDK: Modifying shared link password issues.

AGreenTejada
Helpful | Level 5

Awesome, that just worked. I'm a little uncomfortable dealing with static initializers instead of constructors, but our team will refactor as necessary.

Need more support?