簡體   English   中英

如何以編程方式使用 Airbnb 的 iCalendar 鏈接

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

我獲得了 Airbnb 房源的 iCalendar 鏈接。 當我使用任何瀏覽器訪問該鏈接時,瀏覽器會自動下載.ics iCalendar 文件。 我正在嘗試編寫一個應用程序,該應用程序將與該特定 Airbnb 列表的 iCalendar 同步。 我想我應該只fetch iCalendar 鏈接,我可以讀取 .ics 文件的內容並解析它並處理信息。

但是,當我嘗試在同一個 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

理想情況下,我想從 NODE.js(Next.js)查詢該鏈接,而不是下載 a.ics 文件,我希望能夠以 JSON 格式解析 the.ics 的信息,以便我可以處理數據並找到哪些日期可用,哪些日期不可用於該列表......

我怎樣才能做到這一點?

順便說一句,我使用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 = [];

    }

找到答案....使用 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