orsifrancesco / instagram-without-api-node

A simple Node.js code to get unlimited instagram public pictures by every user without api, without credentials.
https://orsi.me/instagram-without-api/
MIT License
67 stars 10 forks source link

Fix bug: if any post has no text, it crashes (iwa function) #3

Closed JonS-gitgud closed 1 year ago

JonS-gitgud commented 1 year ago

Using the iwa function will crash the whole thing if any of the posts of the instagram user we searched has no caption or no text (Example https://www.instagram.com/p/CmfebZmpg7y/ see OP hasnt written any text)

Getting the following error because el['node']['edge_media_to_caption']['edges'] returns an empty array: Screenshot_1

Quick fix: Using optional chaining so it returns undefined for the posts with no text, without crashing the app. text: el['node']['edge_media_to_caption']['edges'][0]?.['node']['text']