2017-07-18 83 views
0

我想从Cloud Functions Documentation运行第一个例子。 我创建了我的函数,并从文档中直接复制和粘贴示例。谷歌云功能错误 - res.setHeader不是函数

修正:我把示例代码从这里: https://api.ai/docs/getting-started/basic-fulfillment-conversation

我收到的第一误差;

res.setHeader不是函数

然后我试图使用其他函数来设置首标等;

res.writeHead(200, { 'Content-Type': 'application/json' }); 

但是,这也给我同样的错误。 这是我的下面的代码;

/** 
* Cloud Function. 
* 
* @param {object} event The Cloud Functions event. 
* @param {function} callback The callback function. 
*/ 
exports.helloHttp = function helloHttp(req, res) { 
    response = "This is a sample response from your webhook!" //Default response from the webhook to show it's working 

    // res.setHeader('Content-Type', 'application/json'); //Requires application/json MIME type 
    res.writeHead(200, { 'Content-Type': 'application/json' }); 
    //"speech" is the spoken version of the response, "displayText" is the visual version 
    res.send(JSON.stringify({ 
     "speech": response, 
     "displayText": response   
    })); 
}; 

并遵循它在测试控制台上的显示方式;

enter image description here

我失去了一些东西在这里?

回答

0

这是我的虚假错误,我不得不选择创建HTTP触发器。 现在工作正常。

enter image description here