2017-06-25 67 views
1

我似乎無法得到HTTP請求在我的Alexa的技術工作,這裏是有關示例代碼:HTTPS在Alexa的技能要求

var https = require('https'); 

... 

function getTreeFact(callbackFunction){ 


    var url = 'https://alexa.phl.chs.network/treefacts/index.php'; 

    https.get(url, function(res){ 
     var body = ''; 

     res.on('data', function(chunk){ 
      body += chunk; 
     }); 

     res.on('end', function(){ 
      var gameResponse = JSON.parse(body); 
      callbackFunction(gameResponse); 
     }); 
    }).on('error', function(e){ 
    // Handle error 
    }); 
} 

... 

this.getTreeFact(function (responseMessage){ 
    this.emit(':tell', responseMessage.message); 
}); 

我不知道我做錯了,我想我正在提出HTTP請求。我知道這個技能沒有這個功能(只是註釋掉最後三行,並用this.emit(':tell','hello')取代)。

回答

0

Alexa的官方github頁面上有關於api調用的非常全面的文檔。檢查他們的烹飪清單技能文件它涵蓋了所有的獲得和發佈請求https://github.com/alexa/alexa-cookbook

https://github.com/alexa/其他樣品的主要回購。

+0

我試圖使用他們的代碼,但它仍然給我同樣的錯誤。我認爲這是我正在訪問的網站,但只是使用google.com也無法正常工作... 我只是希望它實際上會顯示錯誤消息 –

+0

我嘗試訪問我的瀏覽器上的代碼中的網站,但它似乎它已關閉,試圖google.com將無法正常工作,因爲它不吐出JSON。嘗試使用[此鏈接]進行測試(http://ip.jsontest.com) –

0

對我來說,它看起來像

this.emit(':tell', responseMessage.message); 

應該

this.emit(':tell', responseMessage); 

我看不到任何.message在這

var gameResponse = JSON.parse(body); 

callbackFunction(gameResponse);