Angel Naydenov
Angel Naydenov

Reputation: 75

How to obtain information about the owner of a Dropbox shared file via the API?

I am writing an application where the users are sharing specific files via Dropbox. I am using the REST API. Lets say A shares a file to B. I know that A can share the file by adding B as a member to a file(add_file_member) and that B can check files shared with him by list_received_files. But I can't find a way that B can see who shared the file. It seems reasonable to have access to this info. Is there a way to obtain some account id or a display info for the user A from B perspective?

Upvotes: 1

Views: 1811

Answers (2)

23W
23W

Reputation: 1530

Example for C# Dropbox SDK.

    public async Task<string> GetSharedFileOwnerID(Dropbox.Api.Files.Metadata data, Dropbox.Api.DropboxClient DropboxClient)
    {
        string owner = "";

        var file = data.AsFile;
        if ((file.HasExplicitSharedMembers ?? false) || (file.SharingInfo != null))
        {
            // search the real file owner
            var list = await DropboxClient.Sharing.ListFileMembersAsync(file.Id);
            var list_continue = false;
            do
            {
                var item = list.Users.First(i => i.AccessType.IsOwner);
                if (item != null)
                {
                    owner = item.User.AccountId;
                    break;
                }

                list_continue = (list.Cursor != null);
                if (list_continue)
                {
                    list = await DropboxClient.Sharing.ListFileMembersContinueAsync(list.Cursor);
                }
            }
            while (list_continue);
        }

        return owner;
    }

    public async Task<string> GetSharedFoldeOwnerID(Dropbox.Api.Files.Metadata data, Dropbox.Api.DropboxClient DropboxClient)
    {
        string owner = "";

        var folder = data.AsFolder;
        if (folder.SharedFolderId != null)
        {
            // search the real folder owner
            var list = await DropboxClient.Sharing.ListFolderMembersAsync(folder.SharedFolderId);
            var list_continue = false;
            do
            {
                var item = list.Users.First(i => i.AccessType.IsOwner);
                if (item != null)
                {
                    owner = item.User.AccountId;
                    break;
                }

                list_continue = (list.Cursor != null);
                if (list_continue)
                {
                    list = await DropboxClient.Sharing.ListFolderMembersContinueAsync(list.Cursor);
                }
            }
            while (list_continue);
        }

        return owner;
    }

C# Dropbox SDK is NuGet package. Use Install-Package Dropbox.Api for install it.

Upvotes: 0

Greg
Greg

Reputation: 16940

The SharedFileMetadata object returned by /sharing/list_received_files doesn't include this information, but I'll be sure to pass this along as a feature request.

However, you can use /sharing/list_file_members to list the members of the shared file, as well as their access level (e.g., owner, editor, etc.).

Upvotes: 0

Related Questions