2

I am trying to figure out a method to grab instagram photos without the new API. Here is some code that did not return anything:

const instagramRegExp = new RegExp(/<script 
type="text\/javascript">window\._sharedData = (.*);<\/script>/)

const fetchInstagramPhotos = async (accountUrl) => {
const response = await axios.get(accountUrl)
const json = JSON.parse(response.data.match(instagramRegExp)[1])
const edges = json.entry_data.ProfilePage[0].graphql.user.edge_owner_to_timeline_media.edges.splice(0, 8)
const photos = edges.map(({ node }) => {
return {
  url: `https://www.instagram.com/p/${node.shortcode}/`,
  thumbnailUrl: node.thumbnail_src,
  displayUrl: node.display_url,
  caption: node.edge_media_to_caption.edges[0].node.text
}
})
return photos
}

(async () => {
try {
const photos = await 
fetchInstagramPhotos('https://www.instagram.com/hk.hairstyling/')
const container = document.getElementById('instagram-photos')
photos.forEach(el => {
  const a = document.createElement('a')
  const img = document.createElement('img')

  a.setAttribute('href', el.url)
  a.setAttribute('target', '_blank')
  a.setAttribute('rel', 'noopener noreferrer')
  a.classList.add('instagram-photo')

  img.setAttribute('src', el.thumbnailUrl)
  img.setAttribute('alt', el.caption)

  a.appendChild(img)
  container.appendChild(a)
})
} catch (e) {
console.error('Fetching Instagram photos failed', e)
}
})()
Mr. Hugo
  • 11,887
  • 3
  • 42
  • 60
korykao
  • 63
  • 4
  • Did you made some research? Did you start to code at all? What did you do? Nothing? – Aksen P Dec 17 '19 at 07:12
  • @AksenP yes ive been looking on google and watching videos but im lost... im actually in a Coding Bootcamp. i havent learned php or python or anything like that so im lost. Sorry for being a Noob. Im just trying to practice man.. just trying to build her a site.. – korykao Dec 17 '19 at 07:23
  • @aksenP https://korykao.github.io/HK/ this is it.. just trying to build the profile page. just started working on this today – korykao Dec 17 '19 at 07:23
  • Take a time and read [how to ask here](https://stackoverflow.com/help/how-to-ask) – Aksen P Dec 17 '19 at 07:27
  • You might want to specify 'did not return anything'... why did you expect it to return anything? Try to explain your process. How did you get to this? – Mr. Hugo Dec 17 '19 at 08:47
  • PS. Have you seen this question? https://stackoverflow.com/questions/17373886/how-can-i-get-a-users-media-from-instagram-without-authenticating-as-a-user – Mr. Hugo Dec 17 '19 at 08:49

0 Answers0