2015-06-07 29 views
2

我想了解如何使用Skyscanner Flights API和Google Script。看來,網上提供的信息並不適合像我這樣的新手。Skyscanner Flights API和Google腳本

從我得到了什麼,以獲得對航班的價格的程序是: - 發送有哪些航班,我們希望有關 信息的HTTP POST請求 - 然後發送一個HTTP GET請求,這將給我們價格信息

我想用Google Script做到這一點。

這是到目前爲止我的代碼:

function sky1() { 

    /* 
    Link to Skyscanner.com help : http://business.skyscanner.net/portal/en-    GB/Documentation/FlightsLivePricingList 
    Link to Skyscanner api demo (api key given there): http://business.skyscanner.net/portal/en-  GB/Documentation/FlightsLivePricingQuickStart 
    */ 


    var apikey = "prtl6749387986743898559646983194";// is given on skyscanner website for testing 
    var url = "http://partners.api.skyscanner.net/apiservices/pricing/v1.0/?apikey=" + apikey; 
    // Post http request to skyscanner 
    var post_resp=sendHttpPost(url,apikey); 
    } 


    function sendHttpPost(url) { 
    // post_params 
     var post_params = { 
      "Country": "CH", 
      "Currency": "CHF", 
      "Locale": "en-GB", 
      "Adults": 1, 
      "Children": 0, 
      "Infants": 0, 
      "OriginPlace": "12015", 
      "DestinationPlace": "5772", 
      "OutboundDate": "2015-08-09", 
      "InboundDate": "2015-08-23", 
      "LocationSchema": "Default", 
      "CabinClass": "Economy", 
      "GroupPricing": true 
     }; 

     var options = 
      { 
      "method" : "POST", 
      "contentType" : "application/json", // didn't get what this means 
      "payload" : JSON.stringify(post_params), // didn't get what this means 
      "muteHttpExceptions" : true, // avoids error message 
      }; 

     var post_resp=UrlFetchApp.fetch(url,options); 
     Logger.log(post_resp.getResponseCode()); 

     return post_resp; 
    } 

任何幫助將是非常讚賞。這給了我一個415響應,而不是201表示會話已經創建。 PS:我不是程序員,如果我們保持簡單,我會非常感激。

回答