I'm trying to get public post information from Instagram using this - https://instagram.com/p/{id}?__a=1 link in Node.js using https get request.
The problem is that it works in my local server but as soon as I deploy my code in Vercel server-less function the data event inside https get response never gets fired which leaves my data to be empty string.
const getPostInfo = (url) => {
return new Promise((resolve, reject) => {
let data = "";
https
.get(url, (res) => {
console.log(res.statusCode); // 301
res.on("data", (chunk) => {
data += chunk.toString();
});
res.on("end", () => {
console.log(data); // Empty string
data = JSON.parse(data); // Parse error
resolve(data);
});
})
.on("error", (err) => {
console.log(err);
reject(err);
});
});
};
I've think the problem is with the instagram link it returns status code 301. I have tried some other get requests from other API's and it seems to be working fine.
I've also tried using Array buffer and also used different libraries like request and node-fetch but no luck.
Please tell me what am I doing wrong.
I think it's because in my country (INDIA) the '?__a=1' API works but in other country like USA its requires you to login to Instagram and the default Vercel server is located in USA so the data event never gets fired.