Created
January 22, 2019 12:12
-
-
Save palaa159/c3e1ad48e3205f3631d1546f3f271c60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require('axios') | |
const igHandle = 'jennieramida' | |
const sessionId = '9218400%3AGJqz0Eewttl0x8%3A13' | |
const Cookie = `sessionid=${sessionId}` | |
let i = 0 | |
async function requestUserData () { | |
const url = `https://www.instagram.com/${igHandle}/?__a=1` | |
console.info(`Making request to: ${url}`) | |
const res = await axios.request({ | |
url, | |
method: 'get', | |
headers: { | |
Cookie | |
} | |
}) | |
return res | |
} | |
async function requestPosts ({_userId, cursorHash}) { | |
i++ | |
const userId = _userId | |
const url = `https://www.instagram.com/graphql/query/?query_hash=e6a78c2942f1370ea50e04c9a45ebc44&variables={"id":"${userId}","first":12${cursorHash? ',"after":"' + cursorHash + '"': ''}} | |
` | |
console.info(`${i} Making request to: ${url}`) | |
const res = await axios.request({ | |
url, | |
method: 'get', | |
headers: { | |
Cookie | |
} | |
}) | |
const _posts = res.data.data.user.edge_owner_to_timeline_media | |
console.info(` | |
post_count: ${_posts.count} | |
page_info: ${_posts.page_info} | |
edges: ${_posts.edges} | |
`) | |
if (_posts.page_info.has_next_page) { | |
const cursorHash = _posts.page_info.end_cursor | |
await requestPosts({ | |
_userId: userId, | |
cursorHash | |
}) | |
} | |
} | |
async function run () { | |
const user = (await requestUserData()).data.graphql.user | |
console.info( | |
` | |
biography: ${user.biography} | |
id: ${user.id} | |
username: ${user.username} | |
full_name: ${user.full_name} | |
is_private: ${user.is_private} | |
profile_pic_url: ${user.profile_pic_url_hd} | |
followed_by: ${user.edge_followed_by.count} | |
`) | |
const _userId = user.id | |
await requestPosts({ | |
_userId | |
}) | |
} | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment