首页 > 解决方案 > 如果您在购买 twilio 号码时未捕获它,请稍后获取 twilio 电话号码 SID

问题描述

如果您在购买 twilio 号码时没有捕获它,是否有任何简单的方法可以在以后获取电话号码 SID。

购买号码时很容易捕获电话号码 sid,但我发现以后捕获它的解决方案似乎很复杂并且使用循环。

购买号码时捕获电话号码 SID:

from twilio.rest import Client

account_sid = 'accountsid'
auth_token = 'your_auth_token'
client = Client(account_sid, auth_token)

# Purchase the phone number
number = client.incoming_phone_numbers \
               .create(phone_number=number)

print(number.sid)

标签: pythontwiliotwilio-api

解决方案


您可以使用“完全匹配”进行过滤。

例如,如果您的号码是+17775553333,请尝试使用此代码获取sid

from twilio.rest import Client

account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
client = Client(account_sid, auth_token)

incoming_phone_numbers = client.incoming_phone_numbers.list(phone_number='+17775553333', limit=20)

for record in incoming_phone_numbers:
    print(record.sid)


推荐阅读