【问题标题】:google actions calling http post api using actions-sdk not working谷歌操作使用actions-sdk调用http post api不起作用
【发布时间】:2017-02-23 12:50:35
【问题描述】:

当用户使用操作 sdk 提供一些原始输入时,我试图调用一个 http post api,但我收到错误“操作现在没有响应。请稍后再试”,我的代码如下

if (assistant.getRawInput() == 'test') { 
      request({
        url: url,
        json: true
      }, function (error, response, body) {
          if (error) {          
            assistant.tell('There is some error!');
          }
          else {         
             assistant.tell('we got the response!');
          }
        }
      )

代码没有问题,因为它可以单独使用节点命令完全正常,我是谷歌操作的新手,请协助

【问题讨论】:

    标签: actions-on-google google-home


    【解决方案1】:

    完成请求需要多长时间?操作需要在大约 5 秒内完成,如果您调用的 URL 占用了大部分时间,则操作可能会超时。

    【讨论】:

    • 网址1秒内响应
    • 它肯定是在调用请求逻辑(并且原始输入正是“测试”)?会不会是原始输入不匹配,而您的逻辑的其他部分没有做助手。询问或告诉?
    【解决方案2】:

    我很确定它是如何在请求的回调处理程序中引用助手变量的。尝试在执行回调时控制台记录助手变量(您可以在该函数的谷歌云日志中看到控制台日志),您应该看到它没有定义。尝试使用 ES6 粗箭头语法来访问辅助变量,例如

    if (assistant.getRawInput() == 'test') { 
          request({
            url: url,
            json: true
          }, (error, response, body) => {
              if (error) {          
                assistant.tell('There is some error!');
              }
              else {         
                 assistant.tell('we got the response!');
              }
            }
          )

    【讨论】:

      猜你喜欢
      • 2018-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多