Podio .NET View.Items始终返回零

时间:2017-12-06 12:29:26

标签: podio

使用Podio.NET库(Podio.Async),我试图使用ViewService.GetView()方法获取Podio View对象。 Podio View对象表示Podio应用程序中的预定义视图或一组过滤器。

Podio View对象的一个​​属性(PodioAPI.Models.View)是Items属性,如var noOfItems = myView.Items中所示。但是,对于我来说,这个字段似乎总是为零。

我想我可以使用view-id调用ItemService.FilterItemsByView(),而view-id又返回一个PodioCollection<Item>对象,该对象具有FilteredItems属性,可用于获取项目数量,但这意味着额外的电话。

有没有人有任何想法或信息可以帮助我?

感谢您抽出宝贵时间阅读我的问题,希望您能提供帮助,或者其他人认为这有帮助。

凯恩

示例代码


    class Program
    {
        const string CLIENT_ID = "[Your Client Id]";
        const string CLIENT_SECRET = "[Your Client Secret]";
        const int APP_ID = [Your App Id];
        const string APP_TOKEN = "[Your App Token]";
        const string VIEW_NAME = "[Your View Id]";


        static void Main(string[] args)
        {
            Task.Run(async () => { await Go(); }).GetAwaiter().GetResult();
            Console.ReadKey();
        }


        static async Task Go()
        {
            var client = await GetClient();
            var views = await GetViews(client);
            var view = await GetView(client);
            var viewItems = await GetViewItems(client, view);
        }



        static async Task<View> GetView(Podio client)
        {
            var view = await client.ViewService.GetView(APP_ID, VIEW_NAME);
            Console.WriteLine("View Name: {0}, Id: {1}, Items: {2}",view.Name, view.ViewId, view.Items);
            return view;
        }


        static async Task<List<View>> GetViews(Podio client)
        {
            var views = await client.ViewService.GetViews(APP_ID);
            Console.WriteLine("Views: " + views.Count);
            foreach (var view in views)
            {
                Console.WriteLine(" - ({0}) {1}", view.ViewId, view.Name);
            }
            return views;
        }


        static async Task<List<Item>> GetViewItems(Podio client, View view)
        {
            Console.WriteLine("View Items: " + view.Items);   // This always return 0
            var itemList = new List<Item>();
            var itemsRemaining = true;
            var offset = 0;
            while (itemsRemaining)
            {
                var colItems = await client.ItemService.FilterItemsByView(appId: APP_ID, viewId: Int32.Parse(view.ViewId), offset: offset);
                Console.WriteLine(" Downloaded: {0} to {1}", offset, offset + colItems.Items.Count());
                itemList.AddRange(colItems.Items);
                offset += colItems.Items.Count();

                if (offset >= colItems.Filtered)
                {
                    itemsRemaining = false;
                    break;
                }
            }
            Console.WriteLine("Total View Items Downloaded: " + itemList.Count);
            return itemList;
        }


        static async Task<Podio> GetClient()
        {
            var client = new Podio(CLIENT_ID, CLIENT_SECRET);
            var auth = await client.AuthenticateWithApp(APP_ID, APP_TOKEN);
            Console.WriteLine("Auth expires in: " + auth.ExpiresIn);
            return client;
        }
    }

1 个答案:

答案 0 :(得分:0)

有两种类似的方法:

获取观看次数 https://developers.podio.com/doc/views/get-views-27460
对于返回的每个视图,此方法返回items

"items": The number of items matching the view  

获取视图 https://developers.podio.com/doc/views/get-view-27450
此方法不返回items参数,但您仍可以从groupings param获取该参数(如果有任何分组)。否则 - 不返回视图中的项目数。

"groupings": individual groups data, if grouping is present, otherwise {}
    {
      "total": total count of items in all groups,
      "groups": [{
        "count": items count of the single group,

如果没有分组,您必须致电https://developers.podio.com/doc/items/filter-items-by-view-4540284。然后使用filtered响应值。

 "filtered": Total number of items matching the filter,

如果您只需要过滤项目数量 - 请在您的请求中添加limit=1参数。