Your workflow is unique 👨‍💻 -  tell us how you use Dropbox here.

Forum Discussion

Mark L.45's avatar
Mark L.45
Collaborator | Level 9
10 years ago

API example for SwiftyDropBox v2.0 sharing

#!/usr/bin/python
import dropbox
dbx = dropbox.Dropbox('ab-X')
dbx.users_get_current_account()
for entry in dbx.files_list_folder('/Shared').entries:
    print(entry.name)

# OUTPUT:
dbx.files_download_to_file('Dog.jpg','/Shared/Samba.png')

Tried, signed in ok... and the code compiles, got the user and files part working but sharing no. So my python call to dx.files_list_folder works on my dropbox, but my swift code does nothing?

if let client = Dropbox.authorizedClient {

client.sharing.listFolders().response({ response, error in
            if let link = response {
                print(link.entries)
            } else {
                print("nothing ...")
            }
        })
}

Have I missed something? Can somebody share some working v2 code that does the same thing as the python example?

Using Swift 2.0 under IOS 9.2 with Xcode client 7.1.1 running under El Capitan.

5 Replies

Replies have been turned off for this discussion
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    10 years ago

    To clarify, does the Swift version literally do nothing, or does it print out "nothing ..."? In either case, you should make sure you're handling the error in that else block in the Swift version.

    Also, note that these two aren't really equivalent. In the Python version, files_list_folder('/Shared') is listing the folder at the specific path "/Shared", while the Swift version uses sharing.listFolders which would list any and all shared folders. The equivalent of files_list_folder would be the listFolder file route.

  • Mark L.45's avatar
    Mark L.45
    Collaborator | Level 9
    10 years ago

    OK, clarification. It literally does nothing, it doesn't print anything at all. What I want to do is list the shared folders, so the swift call is the right one; only it doesn't work for me. The Shared folder is a folder I have shared to user B; I also got user B to share a folder with me. I see neither with this call. This is not an app share, its the other sort of share?

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    10 years ago

    What do you mean by "app share"? There are two types of sharing in Dropbox, "shared links" and "shared folders". Shared links won't appear in sharing.listFolders, but shared folders will.

    Anyway, is your client object going out of scope by any chance? The API call is asynchronous, so that could be a reason you're not getting any output.

  • Mark L.45's avatar
    Mark L.45
    Collaborator | Level 9
    10 years ago

    Ok, try again. Lets try with a different example. I run this.

    /usr/bin/curl -X POST https://api.dropboxapi.com/2/sharing/list_folders  --header "Authorization: Bearer ab-X"

    I get this...

    {"entries": [{"path_lower": "/shared", "name": "Shared", "shared_folder_id": "dbsfid:blah", "access_type": {".tag": "owner"}, "is_team_folder": false, "policy": {"acl_update_policy": {".tag": "editors"}, "shared_link_policy": {".tag": "anyone"}}}, {"path_lower": "/myshared", "name": "myShared", "shared_folder_id": "dbsfid:blah", "access_type": {".tag": "editor"}, "is_team_folder": false, "policy": {"acl_update_policy": {".tag": "editors"}, "shared_link_policy": {".tag": "anyone"}}}]}

    Now I want to do that in swift? 

About Dropbox API Support and Feedback

Node avatar for Dropbox API Support and Feedback
Get help with the Dropbox API from fellow developers and experts.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

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, Facebook or Instagram.

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!