【问题标题】:Twilio retrieve message history from recipient only via PythonTwilio 仅通过 Python 从收件人那里检索消息历史记录
【发布时间】:2019-11-17 20:00:38
【问题描述】:
假设我有这段代码,它将 twilio 号码与其收件人之间的所有消息历史记录放在一个数组中。有没有办法只检索所有收件人而不是发件人(我是谁)的邮件历史记录
from twilio.rest import Client
account_sid = 'xxxx'
auth_token = 'xxxx'
client = Client(account_sid, auth_token)
text=[]
messages = client.messages.list()
for record in messages:
print(record.body)
text.append(record.body)
print(text)
【问题讨论】:
标签:
python
python-3.x
twilio
twilio-php
twilio-programmable-chat
【解决方案1】:
有一些filter criteria with the above command 的示例,您可以过滤到:到您的特定 Twilio 号码,以便仅查看对话的那一侧(通过正文键)。
# Download the helper library from https://www.twilio.com/docs/python/install
from datetime import datetime
from twilio.rest import Client
# Your Account Sid and Auth Token from twilio.com/console
# DANGER! This is insecure. See http://twil.io/secure
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
client = Client(account_sid, auth_token)
messages = client.messages.list(
to='+15558675310',
limit=20
)
for record in messages:
print(record.sid)