const userId = "USER_ID"; const queryUrl = "https://www.instagram.com/graphql/query/"; const [followers, following] = [ "37479f2b8209594dde7facb0d904896a", "58712303d941c6855d4e888c5f0cd22f", ]; const fetchOptions = { headers: { cookie: 'INSTAGRAM_COOKIE"', }, }; const fetchFollowersOrFollowing = async (fetchFollowing = false) => { const resultKey = fetchFollowing ? "edge_follow" : "edge_followed_by"; const options = { id: userId, after: "", first: 50, }; const requestUrl = `${queryUrl}?${new URLSearchParams({ query_hash: fetchFollowing ? following : followers, variables: JSON.stringify(options), }).toString()}`; const json = await fetch(requestUrl, { ...fetchOptions, }).then((res) => res.json()); let pageInfo = json.data.user[resultKey].page_info; const results = [...json.data.user[resultKey].edges]; console.log( `${fetchFollowing ? "Takip edilenler" : "Takipçiler"} yükleniyor... (${results.length}/${json.data.user[resultKey].count})`, ); while (pageInfo.has_next_page) { options.after = pageInfo.end_cursor; const requestUrl = `${queryUrl}?${new URLSearchParams({ query_hash: fetchFollowing ? following : followers, variables: JSON.stringify(options), }).toString()}`; const json = await fetch(requestUrl, { ...fetchOptions }).then((res) => res.json(), ); pageInfo = json.data.user[resultKey].page_info; results.push(...json.data.user[resultKey].edges); console.log( `${fetchFollowing ? "Takip edilenler" : "Takipçiler"} yükleniyor... (${results.length}/${json.data.user[resultKey].count})`, ); await new Promise((resolve) => setTimeout(resolve, 1000)); } const followersList = results.map((item) => ({ id: item.node.id, fullname: item.node.full_name, username: item.node.username, image: item.node.profile_pic_url, })); return followersList; }; const prepareData = async () => { try { const followers = await fetchFollowersOrFollowing(); const follows = await fetchFollowersOrFollowing(true); const now = new Date(); console.log({ createdAt: now.toISOString(), data: { followers: { total: followers.length, users: followers, }, follows: { total: follows.length, users: follows, }, }, }); } catch (err) { console.error(err); } }; prepareData();