简体   繁体   English

如何以编程方式使用 Airbnb 的 iCalendar 链接

[英]How to use Airbnb's iCalendar Link Programmatically

I have gotten the iCalendar link of a Airbnb listing.我获得了 Airbnb 房源的 iCalendar 链接。 When I visit that link using any browser, the browser automatically downloads the.ics iCalendar file.当我使用任何浏览器访问该链接时,浏览器会自动下载.ics iCalendar 文件。 I am trying to program an application that will sync with the iCalendar of that particular Airbnb listing.我正在尝试编写一个应用程序,该应用程序将与该特定 Airbnb 列表的 iCalendar 同步。 I thought I should just fetch the iCalendar link and I can read the contents of the.ics file and parse it and process the information.我想我应该只fetch iCalendar 链接,我可以读取 .ics 文件的内容并解析它并处理信息。

However when I try to use isomorphic-fetch on the same Airbnb Calendar link I am getting the following Response:但是,当我尝试在同一个 Airbnb 日历链接上使用isomorphic-fetch时,我得到以下响应:

Response {
  size: 0,
  timeout: 0,
  [Symbol(Body internals)]: {
    body: PassThrough {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      [Symbol(kCapture)]: false,
      [Symbol(kTransformState)]: [Object]
    },
    disturbed: false,
    error: null
  },
  [Symbol(Response internals)]: {
    url: 'https://www.airbnb.com/calendar/ical/22342432.ics?s=56501a678175afddd0ef3874b7a1b28b',
    status: 200,
    statusText: 'OK',
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    counter: 0
  }
}

FetchError: invalid json response body at https://www.airbnb.com/calendar/ical/22342432.ics?s=56501a678175afddd0ef3874b7a1b28b reason: Unexpected token B in JSON at position 0

Ideally I would like to query that link from NODE.js (Next.js) and instead of downloading a.ics file I would like to be able to parse the info of the.ics in JSON format so I can process the data and find out which dates are available and which dates are not available for that listing....理想情况下,我想从 NODE.js(Next.js)查询该链接,而不是下载 a.ics 文件,我希望能够以 JSON 格式解析 the.ics 的信息,以便我可以处理数据并找到哪些日期可用,哪些日期不可用于该列表......

How can I do that?我怎样才能做到这一点?

btw I used isomorphic-fetch npm library to do the fetching...eg顺便说一句,我使用isomorphic-fetch npm 库来进行提取...例如

const response = await fetch(`https://www.airbnb.com/calendar/ical/22342432.ics?s=56501a678175afddd0ef3874b7a1b28b`);
        

        console.log('response');
        console.log(response);

        console.log('response.body', response.body);
        

        stories = await response.json();

        console.log('stories');
        console.log(stories);

        res.status(200).json(stories)

    } catch(err) {
        console.log('error')
        console.log(err)
        stories = [];

    }

Found the answer.... use npm package node-ical找到答案....使用 npm package node-ical

const ical = require('node-ical');
    
    ical.fromURL(url, options, function(err, data) {
        if (err) console.log(err);
        console.log(data);
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM