twilio打电话和发短信

 

# -*- coding: utf-8 -*-
# @Time    : 2018/03/09 14:53
# @Author  : cxa
# @File    : call.py
# @Software: PyCharm
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token can be found at https://www.twilio.com/console
account_sid = "mysid"
auth_token = "token"
client = Client(account_sid, auth_token)

# # Start a msg
# call = client.messages.create(
#     to="+mynumber",
#     from_="+18162811118",
#     body="短信内容"
# )
# Start a phone call
call = client.calls.create(
    to="+mynumber",
    from_="+18162811118",
    url="http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient"
)

print(call.sid)

重要的一步默认没有授权中国地区的需要开启授权,

Account not authorized to call . Perhaps you need to enable some international permissions: twilio.com/user/account/settings/international


打电话的时候会一直报错

twilio.base.exceptions.TwilioRestException: HTTP 400 error: Unable to create record: The number +mynumberis unverified. Trial accounts may only make calls to verified numbers.



最后的解决方案是

Verified Caller IDs:

https://www.twilio.com/user/account/phone-numbers/verified

 

转载于:https://www.cnblogs.com/c-x-a/p/8535115.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 Twilio 发送短信的第一步是在 Twilio 网站上注册一个账户。注册后,你将获得一个账户 SID 和一个认证令牌,这些信息将用于通过 API 连接到 Twilio。 接下来,你需要验证你想要发送短信的号码。在 Twilio 控制台上,转到 "Phone Numbers" 页面,点击 "Verify a Number" 按钮。输入要发送短信的号码,并按照指示进行验证。验证可以通过短信或电话进行。 完成号码验证后,你可以使用 Twilio 的 API 发送短信。你可以使用任何支持 RESTful API 的编程语言来调用 Twilio 的 API。下面是一个使用 Python 和 Twilio Python 库发送短信的示例代码: ```python from twilio.rest import Client # 在 Twilio 控制台中获得的账户 SID 和认证令牌 account_sid = 'your_account_sid' auth_token = 'your_auth_token' # 创建 Twilio 客户端 client = Client(account_sid, auth_token) # 发送短信 message = client.messages.create( body='Hello, this is a test message from Twilio!', from_='your_twilio_phone_number', to='recipient_phone_number' ) print(message.sid) ``` 在上面的代码中,你需要将 `your_account_sid` 和 `your_auth_token` 替换为你在 Twilio 控制台中找到的账户 SID 和认证令牌。还需要将 `your_twilio_phone_number` 替换为你购买的 Twilio 电话号码,将 `recipient_phone_number` 替换为你要发送短信的目标号码。 通过这种方式,你可以使用 Twilio 验证的号码发送短信。记得根据你的需求进行适当的配置和处理错误情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值