Created
December 10, 2025 18:58
-
-
Save PierreAndreis/1eceb9437ede6e339e0ed9f33fb49347 to your computer and use it in GitHub Desktop.
instagram-get-reels-details
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
| (async () => { | |
| // replace this with the shortcode you want to test | |
| const shortcode = "REPLACE_WITH_SHORTCODE"; // e.g. "CxYz1234abc" | |
| const docId = "26130443479876713"; | |
| const appId = "936619743392459"; | |
| const csrfToken = document.cookie.match(/csrftoken=([^;]+)/)?.[1]; | |
| if (!csrfToken) { | |
| console.error("No CSRF token found - are you logged in?"); | |
| return null; | |
| } | |
| // get LSD token (optional but nice to have) | |
| let lsdToken = document.querySelector('input[name="lsd"]')?.value; | |
| if (!lsdToken) { | |
| const scripts = document.querySelectorAll("script:not([src])"); | |
| for (const script of scripts) { | |
| const match = script.textContent?.match( | |
| /"LSD"\s*,\s*\[\]\s*,\s*\{\s*"token"\s*:\s*"([^"]+)"/ | |
| ); | |
| if (match) { | |
| lsdToken = match[1]; | |
| break; | |
| } | |
| } | |
| } | |
| lsdToken = lsdToken || ""; | |
| const variables = JSON.stringify({ shortcode }); | |
| const params = new URLSearchParams({ | |
| av: "17841400136560054", | |
| __d: "www", | |
| __user: "0", | |
| __a: "1", | |
| __req: "1", | |
| dpr: "2", | |
| __ccg: "EXCELLENT", | |
| fb_api_caller_class: "RelayModern", | |
| fb_api_req_friendly_name: "PolarisPostRootQuery", | |
| variables, | |
| doc_id: docId, | |
| }); | |
| if (lsdToken) { | |
| params.set("lsd", lsdToken); | |
| } | |
| console.log("Fetching post data for shortcode:", shortcode); | |
| const response = await fetch("https://www.instagram.com/graphql/query", { | |
| method: "POST", | |
| headers: { | |
| "Content-Type": "application/x-www-form-urlencoded", | |
| "X-CSRFToken": csrfToken, | |
| "X-IG-App-ID": appId, | |
| "X-FB-Friendly-Name": "PolarisPostRootQuery", | |
| "X-Requested-With": "XMLHttpRequest", | |
| }, | |
| body: params.toString(), | |
| credentials: "include", | |
| }); | |
| if (!response.ok) { | |
| console.error(`GraphQL request failed: ${response.status}`); | |
| return null; | |
| } | |
| const data = await response.json(); | |
| const item = data?.data?.xdt_api__v1__media__shortcode__web_info?.items?.[0]; | |
| console.log("Raw response:", data); | |
| console.log("Extracted item:", item); | |
| // some useful fields if it worked | |
| if (item) { | |
| console.log("Caption:", item.caption?.text); | |
| console.log("Shared to FB:", item.is_shared_to_fb); | |
| console.log("View count:", item.view_count || item.play_count); | |
| console.log("Like count:", item.like_count); | |
| } | |
| return item; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment