2015-06-07 30 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:我不是程序员,如果我们保持简单,我会非常感激。

回答