2

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

据我所知,获取航班价格的程序是: - 发送一个 HTTP POST 请求,其中包含我们想要了解哪些航班的信息 - 然后发送一个 HTTP GET 请求,该请求将为我们提供定价信息

我想用谷歌脚本做到这一点。

到目前为止,这是我的代码:

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

4

1 回答 1

2

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

于 2015-06-08T10:32:36.357 回答