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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM