Skyscanner Flights API和Google脚本

时间:2015-06-07 20:47:49

标签: json google-sheets skyscanner

我正在尝试学习如何使用Skyscanner Flights API和Google Script。似乎在线提供的信息不适合像我这样的新手。

从我得到的,获得航班价格的程序是: - 发送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响应rode而不是201表示已经创建了一个会话。

PS:我不是程序员,如果我们保持简单,我将非常感激。

1 个答案:

答案 0 :(得分:2)

Skyscanner API团队。您可能有兴趣在https://github.com/Skyscanner/skyscanner-api-js看到参考Javascript实现。我还建议使用Fiddler(网络跟踪工具)将来自http://business.skyscanner.net/portal/en-GB/Documentation/FlightsLivePricingQuickStart的测试工具的请求/响应与您的代码的请求/响应进行比较。