【问题标题】:Python3 Stripe API to get all customer emailPython3 Stripe API 获取所有客户电子邮件
【发布时间】:2021-04-09 06:16:33
【问题描述】:

Stripe API 似乎不允许我们一次性获取所有客户信息。以下代码可以打印1000个客户的邮件

import stripe

stripe.api_key = "secret"

customer_dict = stripe.Customer.list(limit=1000)

print(customer_dict)

for i in range(len(customer_dict)):

  print(customer_dict.data[i]['email'])

结果:

abc@gmail.com
def@gmail.com
xyz@gmail.com
etc.

但假设我有无限数量的 Stripe 客户,我如何打印他们所有的电子邮件?

如果我使用他们的 auto_paging_iter,它会一直打印出最近的 10 封电子邮件。

customer_dict = stripe.Customer.list(limit=10)

for customer in customer_dict.auto_paging_iter():

  # print(customer_dict)

  for i in range(len(customer_dict)):

    print(customer_dict.data[i]['email'])

谢谢。

【问题讨论】:

    标签: python-3.x stripe-payments


    【解决方案1】:

    您不能使用高于 100 的限制,自动分页迭代器可能是您想要的,但您需要这样做:

    for customer in customer_dict.auto_paging_iter(limit=100):
      print(customer['email'])
    

    customer_dict,作为一个数组,只包含最初的 10 个对象。如果您想为所有客户创建一个包含所有电子邮件的数组,您可以执行以下操作:

    customer_emails = [c['email'] for c in customer_dict.auto_paging_iter(limit=100)]
    

    ...或类似的。

    【讨论】:

      猜你喜欢
      • 2014-12-01
      • 1970-01-01
      • 2019-09-05
      • 2020-01-04
      • 2021-12-28
      • 2019-08-14
      • 1970-01-01
      • 2015-03-01
      • 1970-01-01
      相关资源
      最近更新 更多