我们正在使用 Twilio 发送消息,并希望获取某个号码已发送并由同一号码接收的消息计数。
现在我们正在尝试做一些类似的事情:
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
})
使用 to 字段时始终返回空
其次,我们始终只能获得最多 50 个结果。
有没有办法只使用参数来获取计数而不是消息?
最佳答案
这里是 Twilio 开发者布道者。
恐怕 API 结果不包括结果总数。这是主要出于性能原因而采取的妥协。有一篇博文解释了the decisions made around pagination在这里。
如果您确实需要计算消息数,您可以自己翻阅列表。首先,每页最多可以获取1000条消息,通过setting the PageSize
attribute to 1000 .
使用 Python 帮助程序库,您还可以 iterate through all results using the iter
method, as explained here .
请告诉我这是否有帮助。
关于python - 获取发送到/从某个号码发送的消息总数 - Twilio Python API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40837002/