Twilio凭证问题

huangapple go评论62阅读模式
英文:

Twilio credential issues

问题

这是我的案例。我需要通过Twilio获取短信数据。这是我拥有的信息:
帐户SID 'ACxxxxxxxxx'。由于安全原因,他们不能提供帐户SID的令牌,但设置了API SID和其令牌
API SID 'SKxxxxxxxxxxxxx'。
令牌 'XXXXXXXXXXXXXXXXX'。

我已经弄清楚了如何通过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、令牌)组合不起作用,(帐户SID、令牌)也不起作用。有什么建议吗?

根据库:

import os
from twilio.rest import Client

# 在twilio.com/console查找您的帐户SID和身份验证令牌并设置环境变量。请参阅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)

希望这有帮助。

英文:

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)

答案1

得分: 0

你需要在初始化客户端时提供帐户SID、API密钥和API密钥。这是相关的文档页面

英文:

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.

huangapple
  • 本文由 发表于 2023年3月21日 00:51:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75793123.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定