2017-07-18 10 views
0

Cloud Functions Documentationから最初の例を実行しようとしています。 私は自分の関数を作成し、文字通りドキュメントからサンプルをコピーして貼り付けました。Google Cloud Function Error - res.setHeaderが関数ではありません

修正:私はここからサンプルコードを取った:私が受け取った https://api.ai/docs/getting-started/basic-fulfillment-conversation

最初のエラーがありました。

res.setHeaderそしてIのようなヘッダを設定するために別の機能を使用しようとした機能

ありません。

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

関連する問題