使用IBM Watson语音文本NPM模块难以注册回调URL

时间:2019-05-12 23:39:52

标签: express npm callback ibm-watson speech-to-text

我正在尝试使用Express为IBM SpeechToText服务注册一个回调URL,当我调用SpeechToText.registerCallback时,我一直收到400响应。

我已经确保该URL存在,并按预期通过Postman提供响应。我也知道我的SpeechToText服务具有正确的凭据。

当我使用registerCallback调用端点时,没有看到'challenge_string'记录。

router.get('/callback', (req,res,next) => {
    console.log(req.query.challenge_string);
    return res.status(200);
});

router.post('/newStream', (req,res) => {

var speechToText = new SpeechToTextV1({
        username: <my_username>,
        password: <my_password>,
        url: 'https://stream.watsonplatform.net/speech-to-text/api/'
      });

    const registerCallbackParams = {
        callback_url: 'http://127.0.0.1:8080/callback',
        user_secret: 'ThisIsMySecret',
    };

    speechToText.registerCallback(registerCallbackParams)
    .then(registerStatus => {
        console.log(JSON.stringify(registerStatus, null, 2));
    })
    .catch(err => {
        console.log(registerCallbackParams);
        console.log('error:', err);
    }); 

}```

1 个答案:

答案 0 :(得分:1)

您的回调URL中的主机名似乎是127.0.0.1,它不是公共主机名,而是回送接口的地址。