简体   繁体   English

Dropbox C#API v2列出团队文件夹内容

[英]Dropbox C# API v2 List Team folder contents

Good afternoon, 下午好,

I am trying to get the list of directories from the dropbox API for the team members in business dropbox. 我正在尝试从Dropbox API获取业务Dropbox中团队成员的目录列表。

The documentation seems to be somewhat unclear and frustratingly difficult to get contents. 该文档似乎还不清楚,很难获得内容。 Therefore my code could off somewhat and hence why i am having issues. 因此,我的代码可能会有所偏离,因此为什么我会遇到问题。 I have a development token for both Team and my admin user. 我为团队和管理员用户都有开发令牌。

        using (var client = new DropboxTeamClient("my token"))
        {

            var teamInfo = await client.Team.GetInfoAsync();
            var teamName = teamInfo.Name;
            var numberOfUsers = teamInfo.NumProvisionedUsers;


            var memListResult = await client.Team.MembersListAsync();
            foreach (var m in memListResult.Members)
            {
                var accountId = m.Profile.AccountId;
                var email = m.Profile.Email;
                Console.WriteLine($"Id {accountId} - email is {email}");
            }

            var accId = memListResult.Members.First(x => x.Profile.Email.Equals("myEmail"))
                ?.Profile.AccountId;

            var memId = memListResult.Members.First(x => x.Profile.Email.Equals("myEmail"))
                ?.Profile.TeamMemberId;


            var dbx = client.AsAdmin(memId);



            try
            {
                var full = await dbx.Users.GetCurrentAccountAsync();
                Console.WriteLine("{0} - {1}", full.Name.DisplayName, full.Email);
                await ListRootFolder(dbx, true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }



        }



  private async Task ListRootFolder(DropboxClient dbx)
  {
        var list = await dbx.Files.ListFolderAsync(string.Empty);
        //var tlist = await dbx.

        // show folders then files
        foreach (var item in list.Entries.Where(i => i.IsFolder))
        {
            Console.WriteLine("D  {0}/", item.Name);
        }

        foreach (var item in list.Entries.Where(i => i.IsFile))
        {
            Console.WriteLine("F{0,8} {1}", item.AsFile.Size, item.Name);
        }
  }

No my issue is that i can only ever get what shows in my directory. 我的问题不是,我只能得到目录中显示的内容。 So for example i have logged into the web browser into dropbox i have three directories. 因此,例如,我已经登录Web浏览器进入保管箱,我有三个目录。

|
|- User Dir 'This is my home directory'
|- Team Dir 'This is a directory for the team'
|- Sample folder 

The team has access to the Team dir and sample folder. 团队有权访问团队目录和示例文件夹。 All i would like to do is simply get the list of directories. 我想做的就是简单地获取目录列表。

I must be doing something completely wrong, i have also tried the overrides for dbx.Files.ListFolderAsync i have set includeMountedFolders parameter to true and still only lists two files in my profile. 我必须做的是完全错误的事情,我还尝试了dbx.Files.ListFolderAsync的替代,我已将includeMountedFolders参数设置为true,但仍只在我的配置文件中列出了两个文件。

I have also tried using the user token instead of the Team token and setting asAdmin. 我也尝试过使用用户令牌而不是团队令牌并将其设置为Admin。

Apologies on the code is somewhat untidy i just want to get it working before i refactor. 对代码的道歉有点不整洁,我只想在重构之前使其正常工作。

Any help would be appreciated. 任何帮助,将不胜感激。

Thanks 谢谢

It sounds like you want to access your "team space" . 听起来您想访问“团队空间” You need to explicitly specify this when calling the API. 调用API时,您需要明确指定。 I recommend reading the Namespace Guide , which covers this in detail. 我建议阅读《命名空间指南》 ,其中详细介绍了此内容。

The .NET SDK supports setting the Dropbox-Api-Path-Root header, via DropboxClient.WithPathRoot . .NET SDK支持通过DropboxClient.WithPathRoot设置Dropbox-Api-Path-Root头。

First, you can get the root info from GetCurrentAccountAsync : 首先,您可以从GetCurrentAccountAsync获取根信息:

var accountInfo = await dbx.Users.GetCurrentAccountAsync();
Console.WriteLine(accountInfo.RootInfo.RootNamespaceId);

Then, you can access the team shared space by using DropboxClient.WithPathRoot to set the Dropbox-Api-Path-Root header as desired, like: 然后,您可以通过使用DropboxClient.WithPathRoot设置所需的Dropbox-Api-Path-Root标头来访问团队共享空间,例如:

dbx = dbx.WithPathRoot(new PathRoot.NamespaceId(accountInfo.RootInfo.RootNamespaceId));
var res = await this.client.Files.ListFolderAsync(path: "");
foreach (var entry in res.Entries)
{
    Console.WriteLine(entry.Name);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM