2017-10-11 9 views
0

私はGoogleのアシスタント(ここでは1:https://dialogflow.com/docs/getting-started/basic-fulfillment-conversation)の天気ボット構築するためのAPI.AIチュートリアルを実行しようとしているのgetaddrinfo ENOTFOUNDのAPI Googleクラウド

を私は、成功したすべてのものを作ったAPIの中にボットを作成し、作成しました私のPCにNodeJSをインストールし、Google Cloud Platformなどを接続しました。

次に、World Weather OrganizationのAPIキーを使用してAPI.aiチュートリアルの内容をコピーして、index.jsファイルを作成しました。 )。

しかし、私がボットを使用すると、動作しません。 Google Cloud Platformでは、エラーは常に同じです:

Error: getaddrinfo ENOTFOUND api.worldweatheronline.com api.worldweatheronline.com:80

at errnoException (dns.js:28) 
    at GetAddrInfoReqWrap.onlookup (dns.js:76) 

私は何度も同じエラーが発生します。だから私は実際にAPIに到達していない。私はWWO側(URLなど)から変わったかどうかを見極めましたが、明らかにそうではありませんでした。私はNodeJSを更新しましたが、それと同じ問題です。私はGoogle Cloudプラットフォームを完全にリフレッシュして助けませんでした。

私は本当にデバッグできません。誰でも助けてくれますか?

ここAPI.aiからのコードです:

'use strict'; 
const http = require('http'); 
const host = 'api.worldweatheronline.com'; 
const wwoApiKey = '[YOUR_API_KEY]'; 
exports.weatherWebhook = (req, res) => { 
    // Get the city and date from the request 
    let city = req.body.result.parameters['geo-city']; // city is a required param 
    // Get the date for the weather forecast (if present) 
    let date = ''; 
    if (req.body.result.parameters['date']) { 
    date = req.body.result.parameters['date']; 
    console.log('Date: ' + date); 
    } 
    // Call the weather API 
    callWeatherApi(city, date).then((output) => { 
    // Return the results of the weather API to Dialogflow 
    res.setHeader('Content-Type', 'application/json'); 
    res.send(JSON.stringify({ 'speech': output, 'displayText': output })); 
    }).catch((error) => { 
    // If there is an error let the user know 
    res.setHeader('Content-Type', 'application/json'); 
    res.send(JSON.stringify({ 'speech': error, 'displayText': error })); 
    }); 
}; 
function callWeatherApi (city, date) { 
    return new Promise((resolve, reject) => { 
    // Create the path for the HTTP request to get the weather 
    let path = '/premium/v1/weather.ashx?format=json&num_of_days=1' + 
     '&q=' + encodeURIComponent(city) + '&key=' + wwoApiKey + '&date=' + date; 
    console.log('API Request: ' + host + path); 
    // Make the HTTP request to get the weather 
    http.get({host: host, path: path}, (res) => { 
     let body = ''; // var to store the response chunks 
     res.on('data', (d) => { body += d; }); // store each response chunk 
     res.on('end',() => { 
     // After all the data has been received parse the JSON for desired data 
     let response = JSON.parse(body); 
     let forecast = response['data']['weather'][0]; 
     let location = response['data']['request'][0]; 
     let conditions = response['data']['current_condition'][0]; 
     let currentConditions = conditions['weatherDesc'][0]['value']; 
     // Create response 
     let output = `Current conditions in the ${location['type']} 
     ${location['query']} are ${currentConditions} with a projected high of 
     ${forecast['maxtempC']}°C or ${forecast['maxtempF']}°F and a low of 
     ${forecast['mintempC']}°C or ${forecast['mintempF']}°F on 
     ${forecast['date']}.`; 
     // Resolve the promise with the output text 
     console.log(output); 
     resolve(output); 
     }); 
     res.on('error', (error) => { 
     reject(error); 
     }); 
    }); 
    }); 
} 

答えて

2

ああ、実際には理由がこれまでで最も愚かでした。 Google Cloud Platformで「請求」を有効にしていなかったため、(APIの無料テストを使用しているにもかかわらず)すべてがブロックされていました。彼らはちょうど私のクレジットカード番号が欲しかったそれは今動作する

関連する問題