@@ -58,15 +58,26 @@ Getting started with the Twilio API couldn't be easier. Create a
58
58
59
59
### API Credentials
60
60
61
- The ` Twilio ` needs your Twilio credentials. You can either pass these
61
+ The ` Twilio ` client needs your Twilio credentials. You can either pass these
62
62
directly to the constructor (see the code below) or via environment variables.
63
63
64
+ Authenticating with Account SID and Auth Token:
64
65
``` python
65
66
from twilio.rest import Client
66
67
67
- account = " ACXXXXXXXXXXXXXXXXX"
68
- token = " YYYYYYYYYYYYYYYYYY"
69
- client = Client(account, token)
68
+ account_sid = " ACXXXXXXXXXXXXXXXXX"
69
+ auth_token = " YYYYYYYYYYYYYYYYYY"
70
+ client = Client(account_sid, auth_token)
71
+ ```
72
+
73
+ Authenticating with API Key and API Secret:
74
+ ``` python
75
+ from twilio.rest import Client
76
+
77
+ api_key = " XXXXXXXXXXXXXXXXX"
78
+ api_secret = " YYYYYYYYYYYYYYYYYY"
79
+ account_sid = " ACXXXXXXXXXXXXXXXXX"
80
+ client = Client(api_key, api_secret, account_sid)
70
81
```
71
82
72
83
Alternatively, a ` Client ` constructor without these parameters will
@@ -111,9 +122,9 @@ This will result in the `hostname` transforming from `api.twilio.com` to `api.sy
111
122
``` python
112
123
from twilio.rest import Client
113
124
114
- account = " ACXXXXXXXXXXXXXXXXX"
115
- token = " YYYYYYYYYYYYYYYYYY"
116
- client = Client(account, token )
125
+ username = " ACXXXXXXXXXXXXXXXXX"
126
+ password = " YYYYYYYYYYYYYYYYYY"
127
+ client = Client(username, password )
117
128
118
129
call = client.calls.create(to = " 9991231234" ,
119
130
from_ = " 9991231234" ,
@@ -126,9 +137,9 @@ print(call.sid)
126
137
``` python
127
138
from twilio.rest import Client
128
139
129
- account = " ACXXXXXXXXXXXXXXXXX"
130
- token = " YYYYYYYYYYYYYYYYYY"
131
- client = Client(account, token )
140
+ username = " ACXXXXXXXXXXXXXXXXX"
141
+ password = " YYYYYYYYYYYYYYYYYY"
142
+ client = Client(username, password )
132
143
133
144
message = client.messages.create(to = " +12316851234" , from_ = " +15555555555" ,
134
145
body = " Hello there!" )
@@ -143,10 +154,10 @@ from twilio.http.async_http_client import AsyncTwilioHttpClient
143
154
from twilio.rest import Client
144
155
145
156
async def main ():
146
- account = " ACXXXXXXXXXXXXXXXXX"
147
- token = " YYYYYYYYYYYYYYYYYY"
157
+ username = " ACXXXXXXXXXXXXXXXXX"
158
+ password = " YYYYYYYYYYYYYYYYYY"
148
159
http_client = AsyncTwilioHttpClient()
149
- client = Client(account, token , http_client = http_client)
160
+ client = Client(username, password , http_client = http_client)
150
161
151
162
message = await client.messages.create_async(to = " +12316851234" , from_ = " +15555555555" ,
152
163
body = " Hello there!" )
@@ -161,7 +172,7 @@ Log the API request and response data to the console:
161
172
``` python
162
173
import logging
163
174
164
- client = Client(account, token )
175
+ client = Client(username, password )
165
176
logging.basicConfig()
166
177
client.http_client.logger.setLevel(logging.INFO )
167
178
```
@@ -171,7 +182,7 @@ Log the API request and response data to a file:
171
182
``` python
172
183
import logging
173
184
174
- client = Client(account, token )
185
+ client = Client(username, password )
175
186
logging.basicConfig(filename = ' ./log.txt' )
176
187
client.http_client.logger.setLevel(logging.INFO )
177
188
```
@@ -182,9 +193,9 @@ client.http_client.logger.setLevel(logging.INFO)
182
193
from twilio.rest import Client
183
194
from twilio.base.exceptions import TwilioRestException
184
195
185
- account = " ACXXXXXXXXXXXXXXXXX"
186
- token = " YYYYYYYYYYYYYYYYYY"
187
- client = Client(account, token )
196
+ username = " ACXXXXXXXXXXXXXXXXX"
197
+ password = " YYYYYYYYYYYYYYYYYY"
198
+ client = Client(username, password )
188
199
189
200
try :
190
201
message = client.messages.create(to = " +12316851234" , from_ = " +15555555555" ,
0 commit comments