I have gotten the iCalendar link of a Airbnb listing. When I visit that link using any browser, the browser automatically downloads the.ics iCalendar file. I am trying to program an application that will sync with the iCalendar of that particular Airbnb listing. 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.
However when I try to use isomorphic-fetch
on the same Airbnb Calendar link I am getting the following Response:
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....
How can I do that?
btw I used isomorphic-fetch
npm library to do the fetching...eg
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
const ical = require('node-ical');
ical.fromURL(url, options, function(err, data) {
if (err) console.log(err);
console.log(data);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.