{"slug": "this-is-our-community-this-is-our-family-these-are-our-friends-https-www-youtube", "title": "\"This is our community, this is our family, these are our friends.\" https://www.youtube.com/watch?v=gk7iWgCk14U&t=425s", "summary": "Based on the provided code, the article is a technical guide for a JavaScript script that uses Instagram's internal API to analyze a user's followers and following lists. The script identifies accounts that the user does not follow back and accounts that do not follow the user back. It includes rate-limiting delays and requires the user to input their Instagram username into the code before running it in the browser console.", "body_md": "instagram-follower-following.js\n\n      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.\n      \nLearn more about bidirectional Unicode characters\n\n \n    Show hidden characters\n\nif (window.location.origin !== \"https://www.instagram.com\") {\n\n  window.alert(\n\n    \"Hey! You need to be on the instagram site before you run the code. I'm taking you there now but you're going to have to run the code into the console again.\",\n\n  );\n\n  window.location.href = \"https://www.instagram.com\";\n\n  console.clear();\n\n}\n\nconst fetchOptions = {\n\n  credentials: \"include\",\n\n  headers: {\n\n    \"X-IG-App-ID\": \"936619743392459\",\n\n  },\n\n  method: \"GET\",\n\n};\n\nlet username;\n\nconst sleep = (ms) => new Promise((r) => setTimeout(r, ms));\n\nconst random = (min, max) => Math.floor(Math.random() * (max - min)) + min;\n\n// This function handles all of the pagination logic\n\n// Calls the API recursively until there are no more pages to load\n\nconst concatFriendshipsApiResponse = async (\n\n  list,\n\n  user_id,\n\n  count,\n\n  next_max_id = \"\",\n\n) => {\n\n  let url = `https://www.instagram.com/api/v1/friendships/${user_id}/${list}/?count=${count}`;\n\n  if (next_max_id) {\n\n    url += `&max_id=${next_max_id}`;\n\n  }\n\n  const data = await fetch(url, fetchOptions).then((r) => r.json());\n\n  if (data.next_max_id) {\n\n    const timeToSleep = random(800, 1500);\n\n    console.log(\n\n      `Loaded ${data.users.length} ${list}. Sleeping ${timeToSleep}ms to avoid rate limiting`,\n\n    );\n\n    await sleep(timeToSleep);\n\n    return data.users.concat(\n\n      await concatFriendshipsApiResponse(\n\n        list,\n\n        user_id,\n\n        count,\n\n        data.next_max_id,\n\n      ),\n\n    );\n\n  }\n\n  return data.users;\n\n};\n\n// helper methods to make the code a bit more readable\n\nconst getFollowers = (user_id, count = 50, next_max_id = \"\") => {\n\n  return concatFriendshipsApiResponse(\"followers\", user_id, count, next_max_id);\n\n};\n\nconst getFollowing = (user_id, count = 50, next_max_id = \"\") => {\n\n  return concatFriendshipsApiResponse(\"following\", user_id, count, next_max_id);\n\n};\n\nconst getUserId = async (username) => {\n\n  let user = username;\n\n  const lower = user.toLowerCase();\n\n  const url = `https://www.instagram.com/api/v1/web/search/topsearch/?context=blended&query=${lower}&include_reel=false`;\n\n  const data = await fetch(url, fetchOptions).then((r) => r.json());\n\n  const result = data.users?.find(\n\n    (result) => result.user.username.toLowerCase() === lower,\n\n  );\n\n  return result?.user?.pk || null;\n\n};\n\nconst getUserFriendshipStats = async (username) => {\n\n  const user_id = await getUserId(username);\n\n  if (!user_id) {\n\n    throw new Error(`Could not find user with username ${username}`);\n\n  }\n\n  const followers = await getFollowers(user_id);\n\n  const following = await getFollowing(user_id);\n\n  const followersUsernames = followers.map((follower) =>\n\n    follower.username.toLowerCase(),\n\n  );\n\n  const followingUsernames = following.map((followed) =>\n\n    followed.username.toLowerCase(),\n\n  );\n\n  const followerSet = new Set(followersUsernames);\n\n  const followingSet = new Set(followingUsernames);\n\n  console.log(Array(28).fill(\"-\").join(\"\"));\n\n  console.log(\n\n    `Fetched`,\n\n    followerSet.size,\n\n    \"followers and \",\n\n    followingSet.size,\n\n    \" following.\",\n\n  );\n\n  console.log(\n\n    `If this doesn't seem right then some of the output might be inaccurate`,\n\n  );\n\n  const PeopleIDontFollowBack = Array.from(followerSet).filter(\n\n    (follower) => !followingSet.has(follower),\n\n  );\n\n  const PeopleNotFollowingMeBack = Array.from(followingSet).filter(\n\n    (following) => !followerSet.has(following),\n\n  );\n\n  return {\n\n    PeopleIDontFollowBack,\n\n    PeopleNotFollowingMeBack,\n\n  };\n\n};\n\n// Make sure you don't delete the quotes\n\n// Replace \"example_username\" below with your instagram username\n\n//\n\n// Change this:\n\nusername = \"example_username\";\n\n//\n\n//\n\n//\n\ngetUserFriendshipStats(username).then(console.log);", "url": "https://wpnews.pro/news/this-is-our-community-this-is-our-family-these-are-our-friends-https-www-youtube", "canonical_source": "https://gist.github.com/abir-taheer/0d3f1313def5eec6b78399c0fb69e4b1", "published_at": "2022-12-27 00:11:08+00:00", "updated_at": "2026-05-23 08:39:08.500308+00:00", "lang": "en", "topics": ["developer-tools", "open-source"], "entities": ["Instagram"], "alternates": {"html": "https://wpnews.pro/news/this-is-our-community-this-is-our-family-these-are-our-friends-https-www-youtube", "markdown": "https://wpnews.pro/news/this-is-our-community-this-is-our-family-these-are-our-friends-https-www-youtube.md", "text": "https://wpnews.pro/news/this-is-our-community-this-is-our-family-these-are-our-friends-https-www-youtube.txt", "jsonld": "https://wpnews.pro/news/this-is-our-community-this-is-our-family-these-are-our-friends-https-www-youtube.jsonld"}}