NodeJS Twilio Sync -需要在选项中指定身份

omqzjyyz  于 11个月前  发布在  Node.js
关注(0)|答案(2)|浏览(116)

大家好,我使用twilio语音JavaScript sdk与ngrok,我发现他们的仓库在GitHub的安装进行得很好,当我试图点击启动设备,以获得客户端名称从我的名称生成器js错误显示,我无法获得客户端客户端名称或进行任何调用
我已经用我所有的帐户sid电话号码twiml应用程序sidTwilio API密钥设置了索引js

cmd错误

Error: identity is required to be specified in options
    at new AccessToken (C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\node_modules\twilio\lib\jwt\AccessToken.js:202:19)
    at tokenGenerator (C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\src\handler.js:13:23)
    at C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\src\router.js:7:12
    at Layer.handle [as handle_request] (C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\node_modules\express\lib\router\layer.js:95:5)    at next (C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\node_modules\express\lib\router\route.js:144:13)
    at Route.dispatch (C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\node_modules\express\lib\router\route.js:114:3)
    at Layer.handle [as handle_request] (C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\node_modules\express\lib\router\layer.js:95:5)    at C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\node_modules\express\lib\router\index.js:284:15
    at Function.process_params (C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\node_modules\express\lib\router\index.js:346:12)       
    at next (C:\xampp\htdocs\voice-javascript-sdk-quickstart-node\node_modules\express\lib\router\index.js:280:10)

字符串

ngrok错误当我点击启动设备

HTTP Requests
-------------

GET /quickstart.js             200 OK
GET /twilio.min.js             200 OK
GET /site.css                  200 OK
GET /                          200 OK
GET /                          502 Bad Gateway

config.js

const dotenv = require("dotenv");
const cfg = {};

if (process.env.NODE_ENV !== "test") {
  dotenv.config({ path: ".env" });
} else {
  dotenv.config({ path: ".env.example", silent: true });
}

// HTTP Port to run our web application
cfg.port = process.env.PORT || 3000;

// Your Twilio account SID and auth token, both found at:
// https://www.twilio.com/user/account
//
// A good practice is to store these string values as system environment
// variables, and load them from there as we are doing below. Alternately,
// you could hard code these values here as strings.
cfg.accountSid = process.env.TWILIO_ACCOUNT_SID;

cfg.twimlAppSid = process.env.TWILIO_TWIML_APP_SID;
cfg.callerId = process.env.TWILIO_CALLER_ID;

cfg.apiKey = process.env.TWILIO_API_KEY;
cfg.apiSecret = process.env.TWILIO_API_SECRET;

// Export configuration object
module.exports = cfg;

a9wyjsp7

a9wyjsp71#

你有没有尝试记录cfg对象,看看它是否包含所有预期的值?
您可以在结束config.js文件时执行此操作,如下所示:

console.log(cfg);

// Export configuration object
module.exports = cfg;

字符串

egdjgwm8

egdjgwm82#

迟做总比不做好,我只是遇到了一个类似的问题,想在这里留下一个提示。
对于Node.js客户端twilio的版本4,您现在需要在配置中提供identity属性。

const token = new AccessToken(
  TWILIO_ACCOUNT_SID,
  TWILIO_API_KEY,
  TWILIO_API_SECRET,
  { identity },
);

字符串
如果缺少这个,你会得到上面提到的错误。如果你不能编辑代码,你可以通过添加标识或降级twilio依赖来修复它。

相关问题