简体   繁体   English

通过Stripe API列出所有客户

[英]List all customers via stripe API

I'm trying to get a list of all the customers in my stripe account but am limited by pagination, wanted to know what the most pythonic way to do this. 我正在尝试获取我的Stripe帐户中所有客户的列表,但是受分页的限制,我想知道执行此操作最有效的方法。

customers = []
results = stripe.Customer.list(limit=100)
print len(results.data)
for c in results:
    customers.append(c)
results = stripe.Customer.list(limit=100, starting_after=results.data[-1].id)
for c in results:
    customers.append(c)

This lists the first 200, but then how do I do this if I have say 300, 500, etc customers? 它列出了前200个,但是如果我说有300、500等客户,该怎么办?

Stripe's Python library has an "auto-pagination" feature: Stripe的Python库具有“自动分页”功能:

customers = stripe.Customer.list(limit=100)
for customer in customers.auto_paging_iter():
    # Do something with customer

The auto_paging_iter method will iterate over every customer, firing new requests as needed in the background until every customer has been retrieved. auto_paging_iter方法将遍历每个客户,并在后台根据需要触发新请求,直到检索到每个客户为止。

The auto-pagination feature is documented here (you have to scroll down a bit). 自动分页功能记录在这里 (您必须向下滚动一点)。

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

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