与外部服务通信:内部服务器错误500

时间:2017-11-13 18:05:24

标签: internal-server-error actions-on-google http-status-code-500

我正在尝试向HTTPS服务(https://broker.bronos.net)发出GET请求。此服务是一种与LAN上的客户端通信的API。我无法通过functions.https.get(URL, (s,ss) => {});

开始工作

请帮助 - 我对网络开发非常陌生,更不用说谷歌的行动了。

我使用apiai-starter-app作为基础,功能完全正常,直到我添加上面的行返回内部服务器错误500.

注意:我在向项目添加结算之前已经尝试过,之后也是如此。都没有工作。

编辑: 使用这个

        const https = require('https');

https.get('https://broker.bronos.net/v1/CLIENT_ID/ROOM_NAME/ACTION/PARAM', (resp) => {
  let data = '';

  // A chunk of data has been recieved.
  resp.on('data', (chunk) => {
    data += chunk;
  });

  // The whole response has been received. Print out the result.
  resp.on('end', () => {
            if (requestSource === googleAssistantRequest) {
        sendGoogleResponse(JSON.parse(data).explanation); // Send simple response to user
      } else {
        sendResponse(JSON.parse(data).explanation); // Send simple response to user
      }
  });

}).on("error", (err) => {
                if (requestSource === googleAssistantRequest) {
        sendResponse("Error: " + err.message); // Send simple response to user
      } else {
        sendResponse("Error: " + err.message); // Send simple response to user
      }
});

1 个答案:

答案 0 :(得分:0)

Firebase的功能对免费套餐上的外部API的访问权限有限。升级到Blaze or Flame plans即可进行外部API调用。

启用Firebase Blaze计划+以下代码正常工作

        const https = require('https');

https.get('https://broker.bronos.net/v1/CLIENT_ID/Living%20Room/volume/20', (resp) => {
  let data = '';

  // A chunk of data has been recieved.
  resp.on('data', (chunk) => {
    data += chunk;
  });

  // The whole response has been received. Print out the result.
  resp.on('end', () => {
            if (requestSource === googleAssistantRequest) {
        sendGoogleResponse(JSON.parse(data).explanation); // Send simple response to user
      } else {
        sendResponse(JSON.parse(data).explanation); // Send simple response to user
      }
  });

}).on("error", (err) => {
                if (requestSource === googleAssistantRequest) {
        sendResponse("Error: " + err.message); // Send simple response to user
      } else {
        sendResponse("Error: " + err.message); // Send simple response to user
      }
});