2016-12-01 5 views
0

저는 voiceXML과 Yahoo Weather API를 사용하여 음성 날씨 시스템을 만들려고합니다. 내 프로그램을 개발하기 위해 나는 voxeo 진화를 사용하고 있습니다.VoiceXML에서 Yahoo Weather API 호출

날씨 API를 호출하려면 datavxml 태그에 srcexpr을 사용하고 있습니다. 동적 URL이 필요하기 때문에 (프로그램에서 날씨를 확인하기 위해 사용자에게 도시를 요청합니다).

<?xml version="1.0" encoding="UTF-8"?> 
<vxml version = "2.1"> 
    <form id="mainMenu"> 
     <field name="City"> 
      <prompt> 
       Please, name a spanish city. 
      </prompt> 

      <grammar src="city.grammar"/> 
     </field> 
     <!-- code taken from the javascript example of the yahoo weather api --> 
     <script> 
     <![CDATA[ 
      var callbackFunction = function(data) { 
       var wind = data.query.results.channel.wind; 
       alert(wind.chill); 
      }; 
     ]]> 
     </script> 

     <data srcexpr="https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places where text='"+City+", spain')&callback=callbackFunction"/> 
    </form> 
</vxml> 

이 프로그램은 날씨 API에 연결하기 때문에 data 태그 작동하지 않습니다,하지만 난 이유를 모르는 :

여기 내 코드입니다. 누군가가 왜 실패하고 있는지 알고 있습니까?

답변

0

나는 마침내 야후의 API에 연결하고 그것을 VoiceXML의 submit 태그를 사용하여 호출하는 PHP 스크립트를 만드는 내 문제를 해결했다.

<?php 
    $City = $_REQUEST["City"]; 
    $Day = $_REQUEST["Day"]; 
    $BASE_URL = "http://query.yahooapis.com/v1/public/yql"; 
    $yql_query = 'select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="('.$City.', spain)") and u="c"'; 
    $yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json"; 
    $session = curl_init($yql_query_url); 
    curl_setopt($session, CURLOPT_RETURNTRANSFER,true); 
    $yahooapi = curl_exec($session); 
    $weather = json_decode($yahooapi,true); 

    $weather_resumen = $weather['query']['results']['channel']['item']['forecast']; 

    $weather_today = $weather_resumen[0]['day']; 
    // yahoo api returns an array with the weather for the next week ordered by 
    // day (0 -> today, 1 -> tomorrow...). Function get_day gets the index of 
    // the day the user said 
    $index_weather = get_day($weather_today, $Day); 
    $condition_index = $weather_resumen[$index_weather]['code']; 
    $weather_condition = $cond_met[intval($condition_index)]; 
    $min_temp = $weather_resumen[$index_weather]['low']; 
    $max_temp = $weather_resumen[$index_weather]['high']; 

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; 
?> 
<vxml version="2.1" xml:lang="es-ES"> 
    <form id="form_main"> 
     <block> 
      <prompt> 
       The weather for <?php echo $Day ?> in <?php echo $City ?> is <?php echo $weather_condition ?>. The lowest temperature will be <?php echo $min_temp ?> and the highest <?php echo $max_temp ?>. 
       <break/> 
      </prompt> 
     </block> 
    </form> 
</vxml>