We're making changes to the Community, so you may have received some notifications - thanks for your patience and welcome back. Learn more here.

Forum Discussion

Peter D.51's avatar
Peter D.51
New member | Level 1
9 years ago

Python API for Dropbox

Trying to produce a Python script to manipulate sharing of folders between Dropbox accounts.  The Tutorial is not present, and the APIs doe not seem to provide a mechanism to build a Members data structure to provide to the sharing classes.

a suitable example or pointer to appropriate documentation would be most useful

thank you

Peter

  • Here is a brief sample with the functionality that you want:

    import sys
    import dropbox

    print 'Running'

    dbx = dropbox.Dropbox('<GENERATED ACCESS TOKEN FROM MY APPS PAGE>')
    curr_account = dbx.users_get_current_account()

    shared_folder_name = '<SHARED FOLDER NAME>'

    # Create a shared folder
    launch = dbx.sharing_share_folder('/' + shared_folder_name)

    if not launch.is_complete():
    print 'Shared folder creation failed, exiting'
    sys.exit(-1)

    meta_data = launch.get_complete()
    member_select = dropbox.sharing.MemberSelector.email('<INVITEE EMAIL>')
    access_level = dropbox.sharing.AccessLevel.editor
    add_member = dropbox.sharing.AddMember(member_select, access_level)

    dbx.sharing_add_folder_member(meta_data.shared_folder_id, [add_member],
    custom_message="<CUSTOM EMAIL MESSAGE>")
  • Peter D.51's avatar
    Peter D.51
    New member | Level 1
    thanks, that worked fine, and should help me put the rest of the documentation into context. all the best Peter
  • Peter D.51's avatar
    Peter D.51
    New member | Level 1

    Another one on the Python API or perhaps needs the HTTP API.

    The remote folders need to be stored in a sub folder. it would be most convenient to allow the app initiating the share to move the remote account's folder. 

    is this functionality supported?

    thanks

    Peter

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

    No, your app would need to be authorized to the other user's account to perform a move operation there.

  • Peter D.51's avatar
    Peter D.51
    New member | Level 1

    Hi Gregory,

    I understand that the connection to the account would need to be authorised, that is not a problem as both the initiator of the request and the target client are connected, it is not a general purpose application.

    Can the initiator of the request talk directly to the target user account to perform the action so the folder is moved without the target user needing to perform any action?

     

    thanks

    Peter

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

    I'm not sure I follow what you mean, but if your app has access tokens for both users, the app perform the necessary API calls in the relevant accounts programmatically, without user interaction.

  • Peter D.51's avatar
    Peter D.51
    New member | Level 1

    Hi Gregory,

    the aim is to have the application on a single machine manipulating a set of shared folders between a number of accounts.

    the application can create a shared folder with an account, is there a programmatic way to obtain permission/access token to allow the folder to be moved. 

    would the application need a list of access tokens generated from a webpage logged into the dropbox account?

    Thanks

    Peter

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

    There isn't a programmatic way for obtaining an access token for an account. The user must explicitly authorize the app. Apps can store and re-use access tokens though. If your app has done this, and has an access token for the necessary accounts, then it can use the file/folder moving API call to move the shared folder as desired.

    Access tokens are sensitives pieces of data though and should be handled securely, since they allow access to Dropbox accounts. So, for a web app, this is reasonably safe, since all of the access tokens would just be stored on the server and you can implement access control as necessary. However, for a client-side app, every instance of the app should only have access tokens for those local users. I.e., one user shouldn't be able to access another user's access token.

  • Peter D.51's avatar
    Peter D.51
    New member | Level 1

    Hi Gregory,

     

    much appreciate your assistance with this.

    So for a an application running on one machine linked to a dropbox account, to 'move' the shared folder of another account, the account would need to use the function on the Dropbox website (logged in as that user) to allow the named APP to have access to the account, and that key opens up the file APIs on the target machine.

    I think I have an angle to explore and see how practical it is.

    thanks

    Peter

     

About Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,875 PostsLatest Activity: 2 years ago
323 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!