From the Phone Numbers page, click ** Buy Phone Numbers ** to go to the purchase page.
You need a ** US phone number ** to send an SMS.
Select a purpose and search for a phone number.
A list of phone numbers and capabilities will be displayed, so purchase an appropriate one. The amount is about $ 1 to $ 2. For some reason, you can purchase with a trial account without registering a card. Strange.
Once you have the phone number, send an SMS. Fill in the form with API Explorer and click ** Issue Request ** at the bottom of the screen. Click to send.
To send programmatically, get the SID and AuthToken from the account settings page and send them using Support Library on github. The credentials are like this.
Copy and use the sample code presented in API Explorer.
from twilio.rest import TwilioRestClient
# put your own credentials here
ACCOUNT_SID = "[SID]"
AUTH_TOKEN = "[AuthToken]"
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
client.messages.create(
to="12345678",
from_="87654321",
body="hello! it's a twilio!",
)
If the request is successful, twilio.rest.resources.messages.Message
will be returned. result.status
seems to be queue
.
If the request fails, TwilioRestException
is thrown. Useful because the error message has a detailed reason.
TwilioRestException:
HTTP Error Your request was:
POST https://api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxxxx/Messages.json
Twilio returned the following information:
Message body is required.
More information may be available here:
https://www.twilio.com/docs/errors/21602
Recommended Posts