# -*- 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