如何在 Twilio 中获取按国家/地区筛选的电话号码列表?

问题描述 投票:0回答:1

我使用 Flask 和 Python 与 Twilio 进行通话。我需要拨打不同国家/地区的电话,因此我有来自不同国家/地区的号码列表。我想使用与我拨打电话所在国家/地区相同的电话号码。

我知道我可以通过以下方式获取我的号码列表:

phone_numbers = client.incoming_phone_numbers.list(page_size=1000)

for phone in phone_numbers:
    print("phone_number: ", phone.phone_number)

有没有办法过滤

phone_numbers
列表,以便我只获取来自特定国家/地区的号码?比如:
client.incoming_phone_numbers.list(country='US', page_size=1000)

我的最后手段是使用国家/地区代码列表检查电话号码字符串的开头,但这并不理想。

python twilio twilio-api
1个回答
0
投票

是的,这是可能的。您可以使用

phoneNumber
属性来过滤数字。请注意,您需要指定部分数字并使用“*”作为任何数字的通配符。因此,您需要知道电话号码中的位数,而不能仅针对国家/地区代码进行过滤。

phone_numbers = client.incoming_phone_numbers.list( phone_number="+49157********")
print(f"Found {len(phone_numbers)} phone numbers")

# print all numbers
for record in phone_numbers:
    print(record.sid, record.phone_number)
© www.soinside.com 2019 - 2024. All rights reserved.