[英]Twilio authentication on AWS Lambda with Node.js
我想使用Node.js https模塊向Twilio的api進行身份驗證。 我的代碼本質上是:
const options = {
host: 'api.twilio.com',
path: '/2010-04-01/Accounts/' + TWILIO_ACCOUNT + '/Messages.json',
auth: {
user: TWILIO_ACCOUNT,
pass: TWILIO_API_KEY
}
};
const req = https.get(options, (res) => { ...
我收到的錯誤是TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object
。 如果我在選項中刪除auth
參數:
const options = {
host: 'api.twilio.com',
path: '/2010-04-01/Accounts/' + TWILIO_ACCOUNT + '/Messages.json'
};
const req = https.get(options, (res) => { ...
我收到的錯誤是Authentication Error - No credentials provided
。 這使我相信我沒有在選項中正確通過身份驗證。
(使用request-promise
,這種通過身份驗證的方法有效;我試圖查看是否可以使用Node.js內置模塊使其工作)
Twilio開發人員布道者在這里。
options
對象中的auth
屬性要求其值是一個string
(請參閱此處可以使用的選項 )。
因此,要更正options
對象,您需要使用冒號將Account SID和Auth Token連接起來,如下所示:
const options = {
host: 'api.twilio.com',
path: '/2010-04-01/Accounts/' + TWILIO_ACCOUNT + '/Messages.json',
auth: `${TWILIO_ACCOUNT}:${TWILIO_API_KEY}`
}
讓我知道是否有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.