如何在我的Android应用程序中使用woocommerce rest api进行自定义分页? [英] How to do custom pagination using woocommerce rest api in my android app?

查看:75
本文介绍了如何在我的Android应用程序中使用woocommerce rest api进行自定义分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android应用中,我正在使用woocommerce rest api从库存中获取产品.按照文档默认情况下,返回多个项目的请求将被分页为10个项目."我需要为每个请求获取25个项目.根据文档,我尝试了很多事情,但不幸的是我没有获得任何成功.

In my android app I am using woocommerce rest api to fetch products from my inventory. As per the documentation "Requests that return multiple items will be paginated to 10 items by default." I need to fetch 25 items per request. As per the documentation I have tried many things but unfortunately I didn't get any success.

我尝试过分页

"mysite/wc-api/v3/products/"+"?page="+pageNum;

使用此方法,我得到前10个产品的pageNum = 1, 11-20,即使用pageNum = 2的下一组10个项目,依此类推.我需要每页获取25个项目.

Using this I get first 10 products for pageNum = 1, 11-20 i.e next set of 10 items using pageNum = 2 and so on. I need to get 25 items per page.

我尝试使用

"mysite/wc-api/v3/products?filter[limit]="+25;

但是这将返回前25个项目.现在,我如何获得下一组25个项目,即26到50个项目.

but this returns me the first 25 items. Now, how do I get the next set of 25 items i.e. 26 to 50 items.

我不能使用

"mysite/wc-api/v3/products?filter[limit]="+50;

因为它会给我前50个项目.

as it would give me the first 50 items.

我指的是 https://woocommerce.github.io/woocommerce-rest -api-docs/

我只需要端点.

推荐答案

最后我自己找出解决方案:

Finally I figured out the solution myself:

这是如果我们需要为每个请求获取25个项目.

This is if we need to get 25 items for each request.

端点类似于:

"mysite/wc-api/v3/products?filter[limit]=25&filter[offset]="+offset;

这将一次性提供25个项目,在每个请求中,我需要发送偏移量,即在每个后续请求中都将发送0,25,50,75 ....

This will give 25 items in one go and in each request I need to send the offset i.e. that will be 0,25,50,75..... at each subsequent request.

这篇关于如何在我的Android应用程序中使用woocommerce rest api进行自定义分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆