Skip to content

Instantly share code, notes, and snippets.

@fabsrc
Created October 31, 2017 16:03
Show Gist options
  • Save fabsrc/c4e370a8dc2fa57f2e07815d7197d769 to your computer and use it in GitHub Desktop.
Save fabsrc/c4e370a8dc2fa57f2e07815d7197d769 to your computer and use it in GitHub Desktop.
Get Instagram URLs by hashtag
function getURLsByHashtag(hashtag) {
let count = 0
let urls = []
return (function makeRequest(maxId = '') {
return fetch(`https://www.instagram.com/explore/tags/${hashtag}/?__a=1&max_id=${maxId}`)
.then(res => res.json())
.then(res => {
console.log(++count)
if (res.tag.media.count > 0) {
urls = urls.concat(res.tag.media.nodes.map(n => 'https://www.instagram.com/p/' + n.code))
}
if (res.tag.media.page_info.has_next_page) {
const maxId = res.tag.media.page_info.end_cursor
return makeRequest(maxId)
} else {
return urls
}
})
})()
}
getURLsByHashtag('enterhashtag')
.then(urls => document.body.innerHTML = urls.join('<br>'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment