So Im trying to get insta posts by url
This is my code:
const data = get('${url}'})
console.log(data)
Data that i get in console (post with only 1 picture):
[
{
media: "example.com"
}
]
const items = data.media
so the issue is right here:
const Post_MP4 = items.map((item, index) => {
if(item && item.includes(".mp4"))
return ({name: 'video${index}.mp4', attachment: item})
else if(item && item.includes(".jpg"))
return ({name: 'image${index}.jpg', attachment: item})
}).filter(item => item)
When the insta post has only 1 picture i get an error(items.map is not a function) but when the post has more than 1 picture I dont get any error.
Data when the post has more than 1 picture:
{
media: ["example", "example2"]
}
What can I do to not get any error by using this code. Thank you.