SMS API 示例代碼通過使用帳戶 SID 和身份驗證令牌創建客戶端會話來作業:
const client = require('twilio')(accountSid, authToken);
然而,在此處顯示的示例代碼中, aclient正在使用 accountSid、API Key 和 API Secret 進行初始化:
const client = require('twilio')(twilioApiKey, twilioApiSecret, {
accountSid: twilioAccountSid });
但是將其與 SMS 服務憑據一起使用無法進行身份驗證。
SMS API 是否只能使用帶有身份驗證令牌的 accountSid 進行身份驗證?
uj5u.com熱心網友回復:
我認為您的第二個代碼示例應該可以作業。請確保 ApiKey、ApiSecret 和 AccountSid 已設定并與您帳戶上的資訊匹配。
嘗試擴展您的代碼:
const accountSid = "...";
const apiKey = "...";
const apiSecret = "...";
const client = require('twilio')(apiKey, apiSecret, { accountSid: accountSid });
client.messages
.create({
body: 'Hello from Node',
to: '<put your phone number here>', // Text this number
from: '<put the account phone number here>', // From a valid Twilio number
})
.then((message) => console.log(message.sid));
如果成功,這應該記錄訊息 ID。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/520707.html
上一篇:如何創建用于身份驗證的中間件
