获取发送到/来自某个号码的邮件总数 - Twilio Python API

问题描述:

我们使用Twilio发送邮件并希望获得已由号码发送并由相同号码接收的邮件计数。获取发送到/来自某个号码的邮件总数 - Twilio Python API

现在我们正在努力做沿线喜欢的东西:但是我们正在运行到2个问题

messagesTo = twilioClient.messages.list({ 
        "DateSent>" : startDate, 
        "DateSent<" : endDate, 
        "to"   : number 
        }) 

messagesFrom = twilioClient.messages.list({ 
        "DateSent>" : startDate, 
        "DateSent<" : endDate, 
        "from_"  : number 
        }) 

count = len(messagesTo) + len(messagesFrom) 

首先,

twilioClient.messages.list({ 
       "DateSent>" : startDate, 
       "DateSent<" : endDate, 
       "to"   : number 
       }) 

总是返回空与向现场使用

第二,我们总是得到最多只有50个结果。

有没有办法只使用参数来获得计数,而不是消息?

Twilio开发者布道者在这里。

恐怕API结果不包括结果总数。这主要是出于性能原因而采取的妥协。这里有一篇博客文章解释了the decisions made around pagination

如果您确实需要计算这些消息,则可以自己浏览列表。首先,您可以通过setting the PageSize attribute to 1000获得每页1000条消息。

使用Python帮助程序库,您也可以使用iterate through all results using the iter method, as explained here

让我知道这是否有帮助。

+0

谢谢你。 iter方法是否允许像Python Helper中的列表一样使用'to','from_'和'dateSent'? – Dfranc3373

+1

[It sure does!](https://github.com/twilio/twilio-python/blob/master/twilio/rest/resources/messages.py#L146-L147) – philnash