如何使用PHP在Shopify Rest API中创建分页 [英] How to create pagination in shopify rest api using php
问题描述
我在php中创建了curl以用于shopify产品其余API.现在我要在其中创建分页.
I created curl in php for use shopify product rest API. Now I want to create pagination in that.
如何创建?
Link: "<https://{shop}.myshopify.com/admin/api/{version}/products.json?page_info={page_info}&limit={limit}>; rel={next}, <https://{shop}.myshopify.com/admin/api/{version}/products.json?page_info={page_info}&limit={limit}>; rel={previous}"
如何使用链接?
谢谢
推荐答案
从API版本2019-07开始,您确实确实需要使用基于游标的分页.
As of API version 2019-07 you do indeed need to use cursor based pagination.
首先进行普通的API调用,包括标头响应.
First make a normal API call, include the header response.
然后在标题响应中,您将看到link:...以及下一个或上一个rel.
Then in the header response you will see link : ... with rel next or previous.
提取page_info,然后再次调用page_info.
Extract the page_info and then make another call with page_info.
第一个电话是这样的:
https://...:...@xyz.myshopify.com/admin/api/2019-10/products.json?limit=2&published_status=published
然后第二个电话是
https://...:...@xyz.myshopify.com/admin/api/2019-10/products.json?limit=2&page_info=asdfas1321asdf3as1f651saf61s3f1x32v1akjhfasdj
当您拨打第二个电话时,请删除所有文件管理器,因为将从第一个电话中应用过滤器.
When you make the second call, remove any filers as the filters will be applied from the first call.
顺便说一句:如果您在浏览器中进行的测试由于链接位于尖括号中而被隐藏,那么只需在开发人员环境中查看源代码即可.
Btw: if your testing in a browser due to the way the link is in angle brackets, it will be hidden, so just view source code in your developer environment.
参考: https://help.shopify.com/en /api/guides/paginated-rest-results
这篇关于如何使用PHP在Shopify Rest API中创建分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!