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: 

Generate links and passwords with Python

Generate links and passwords with Python

rf27
New member | Level 2

Hi,

 

I am looking to generate shared links with individual passwords for a lot of folders in one directory in Dropbox. Could you please give me some starter code or point me to more information for doing this?

 

Basically I would like to be able to loop through all the folder in a directoy, generate a share link for each with a unique password (either generated by Dropbox or supplied using some sort of randomiser function), and then saving these to a CSV.

 

If you could point me in the right direction that would be great.

 

Thanks

7 Replies 7

Greg-DB
Dropbox Staff

If you're using Python, we recommend using the official Dropbox Python SDK. In that, you can use the sharing_create_shared_link_with_settings method to create a shared link for any file or folder. Here's an example of using that method:

 

import datetime

import dropbox

dbx = dropbox.Dropbox("<ACCESS_TOKEN>")

expires = datetime.datetime.now() + datetime.timedelta(days=30)
requested_visibility = dropbox.sharing.RequestedVisibility.team_only
desired_shared_link_settings = dropbox.sharing.SharedLinkSettings(requested_visibility=requested_visibility, expires=expires)

shared_link_metadata = dbx.sharing_create_shared_link_with_settings("/test.txt", settings=desired_shared_link_settings)

print(shared_link_metadata)

`<ACCESS_TOKEN>` should be replaced with the access token.

 

 In your case, you'd want to use RequestedVisibility.password instead of team_only.

dbower
New member | Level 2

Most of the links in the above message no longer work.  Is it possible to re-link the references, or delete the message?

Greg-DB
Dropbox Staff

@dbower Thanks for letting me know! I've updated my post to fix those issues.

ShawnLyu
Explorer | Level 3
Hi Greg, I've tried your code but got exception with the following message:
dropbox.exceptions.ApiError: ApiError('e41bbb442f5b1b4fb6288eb2aa37c87e', CreateSharedLinkWithSettingsError(u'settings_error', SharedLinkSettingsError(u'not_authorized', None))).
I've no clues what's the problem and could you help me with this?
Thanks!

Greg-DB
Dropbox Staff

@ShawnLyu You can find more information about the SharedLinkSettingsError.not_authorized error in the documentation here:

 

https://dropbox-sdk-python.readthedocs.io/en/latest/moduledoc.html#dropbox.sharing.SharedLinkSetting...

 

In short, you'll get that if you try to use a setting that isn't available to the account for the access token you're using. Free accounts can't set link passwords or expirations, for example.

ShawnLyu
Explorer | Level 3
Thanks for your information and that helps a lot!
I got another problem and it would be great if you could help with it:
I've developing a website where clients would request for access to certain files/folders. In this case I wish I could generate shared links with passwords and expire date for each of them differently, say they would each get a unique accessible link with password which would be valid within certain dates.
However, I would get shared link exists errors when I try to generate sharing links for files/folders that have one already.
So do you provide any solutions targeting this scenario?

Greg-DB
Dropbox Staff

@ShawnLyu It's not possible to create more than one distinct shared link per single file or folder, but I'll pass this along as a feature request. 

 

That being the case, you'd need to either use the same shared link for each client, or make a copy of the file or folder for each client (and make a shared link for each copy).

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    ShawnLyu Explorer | Level 3
What do Dropbox user levels mean?