This is my case. I need to fetch SMS data through Twilio. This is what I have: Account SID 'ACxxxxxxxxx' For security reason, they could not give me the token for the Account SID, but setup a API Sid and its token API SID 'SKxxxxxxxxxxxxx' Token 'XXXXXXXXXXXXXXXXX'
I already figured out how to access the data through CURL command, like this:
curl -X GET "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json?PageSize=20" \
-u $API_ACCOUNT_SID:$TOKEN
What if I want to fetch data through the twilio library, what should I setup the connection? (API SID, token) pair does not work. and the (Account SID, token) doesn't work either. Any suggestions?
According to the library
import os
from twilio.rest import Client
# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
messages = client.messages.list(limit=20)
for record in messages:
print(record.sid)
You need to supply the account SID, API key, and API secret when you initialize the client.
import os
from twilio.rest import Client
# Find your Account SID at twilio.com/console
# Provision API Keys at twilio.com/console/runtime/api-keys
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
api_key = os.environ['TWILIO_API_KEY']
api_secret = os.environ['TWILIO_API_SECRET']
client = Client(api_key, api_secret, account_sid)
messages = client.messages.list(limit=20)
for record in messages:
print(record.sid)
This is the relevant docs page.