Skip to content

Instantly share code, notes, and snippets.

@TomGalla11
Created September 10, 2020 11:15
Show Gist options
  • Save TomGalla11/abfc9f235b698d38a2df363414547f8e to your computer and use it in GitHub Desktop.
Save TomGalla11/abfc9f235b698d38a2df363414547f8e to your computer and use it in GitHub Desktop.
IGGetLatestPosts
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, 6)
const photos = edges.map(({ node }) => {
return {
url: `https://www.instagram.com/p/${node.shortcode}/`,
shortcode:
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/dieweltentdecker/')
const container = document.getElementById('instagram-photos')
photos.forEach(el => {
console.log(el.shortcode)
//el.Url
})
} catch (e) {
console.error('Fetching Instagram photos failed', e)
}
})()
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap-reboot.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment