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