python Twilio凭据问题

mkh04yzy  于 2023-03-21  发布在  Python
关注(0)|答案(1)|浏览(93)

这是我的案例。我需要通过Twilio获取短信数据。这是我的:帐户SID 'ACxxxxxxxxx'出于安全原因,他们不能给予我帐户SID的令牌,但设置API SID及其令牌API SID 'SKxxxxxxxxxxxxx'令牌'XXXXXXXXXXXXXXX'
我已经知道如何通过CURL命令访问数据,如下所示:

curl -X GET "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json?PageSize=20" \
-u $API_ACCOUNT_SID:$TOKEN

如果我想通过twilio库获取数据,我应该设置什么连接?(API SID,token)对不起作用。(Account SID,token)也不起作用。有什么建议吗?
根据图书馆

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)
o7jaxewo

o7jaxewo1#

初始化客户端时,需要提供帐户SID、API密钥和API secret。

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)

这是相关文档页面。

相关问题