gpt4 book ai didi

javascript - 为什么使用 Twilio 会收到意想不到的 token ?

转载 作者:行者123 更新时间:2023-11-29 20:41:46 24 4
gpt4 key购买 nike

给定来自 Twilio 的示例代码:

const accountSid = 'ACf37a37065e79fb1a7a594f294cb3b190';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.messages
.create({
body: 'This is the ship that made the Kessel Run in fourteen parsecs?',
from: '+15017122661',
to: '+15558675310'
})
.then(message => console.log(message.sid));

如何获取错误代码和错误信息?

这是输出(根据快速指南)

{
"account_sid": "ACf37a37065e79fb1a7a594f294cb3b190",
"api_version": "2010-04-01",
"body": "This is the ship that made the Kessel Run in fourteen parsecs?",
"date_created": "Thu, 30 Jul 2015 20:12:31 +0000",
"date_sent": "Thu, 30 Jul 2015 20:12:33 +0000",
"date_updated": "Thu, 30 Jul 2015 20:12:33 +0000",
"direction": "outbound-api",
"error_code": null,
"error_message": null,
"from": "+15017122661",
"messaging_service_sid": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"num_media": "0",
"num_segments": "1",
"price": -0.00750,
"price_unit": "USD",
"sid": "MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"status": "sent",
"subresource_uris": {
"media": "/2010-04-01/Accounts/ACf37a37065e79fb1a7a594f294cb3b190/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media.json"
},
"to": "+15558675310",
"uri": "/2010-04-01/Accounts/ACf37a37065e79fb1a7a594f294cb3b190/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json"
}

我正在尝试这个:

client.messages
.create({
body: 'This is the ship that made the Kessel Run in fourteen parsecs?',
from: '+15017122661',
to: '+15558675310'
})
.then(message => console.log(message.sid));
.then(message => console.log(message.error_code));

但是不起作用。我得到了意想不到的 token 。理想情况下,我想记录错误代码和消息以及其他信息,如 date_sent 等。所以我验证并将正确的信息发送回客户端。

任何帮助将不胜感激。

谢谢

最佳答案

你得到 token 的东西是因为你在两个 then() 之间有一个分号(观察第一行的结尾和第二行的开头在下面的代码中)

  .then(message => console.log(message.sid)); // <----
.then(message => console.log(message.error_code));

所以,尝试这样的事情:


client.messages
.create({
body: 'This is the ship that made the Kessel Run in fourteen parsecs?',
from: '+15017122661',
to: '+15558675310'
})
.then(message => {
console.log(message.sid);
console.log(message.error_code || 'no error');
});

关于javascript - 为什么使用 Twilio 会收到意想不到的 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55227884/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com