0% found this document useful (0 votes)
86 views

code instagram

The document contains JavaScript code that defines two asynchronous functions, `search` and `next`, which fetch media data from Instagram's API based on a location ID. The `search` function retrieves media information and handles pagination if more data is available, while the `next` function fetches additional media based on provided parameters. Finally, an immediately invoked function expression (IIFE) executes the `search` function and displays the results in an HTML table format on the webpage.

Uploaded by

Gaming XD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

code instagram

The document contains JavaScript code that defines two asynchronous functions, `search` and `next`, which fetch media data from Instagram's API based on a location ID. The `search` function retrieves media information and handles pagination if more data is available, while the `next` function fetches additional media based on provided parameters. Finally, an immediately invoked function expression (IIFE) executes the `search` function and displays the results in an HTML table format on the webpage.

Uploaded by

Gaming XD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

async function search(loc_id) {

const res = await


fetch(`https://www.instagram.com/api/v1/locations/web_info/?location_id=$
{loc_id}&show_nearby=false&skip_recent_tab=false`, {
"headers": {
"accept": "/",
"accept-language": "en-US,en;q=0.9,id;q=0.8",
"cache-control": "no-cache",
"pragma": "no-cache",
"priority": "u=1, i",
"sec-ch-prefers-color-scheme": "dark",
"sec-ch-ua": "\"Not/A)Brand\";v=\"8\", \"Chromium\";v=\"126\"",
"sec-ch-ua-full-version-list":
"\"Not/A)Brand\";v=\"8.0.0.0\", \"Chromium\";v=\"126.0.6478.56\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-model": "\"\"",
"sec-ch-ua-platform": "\"Linux\"",
"sec-ch-ua-platform-version": "\"6.1.0\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-asbd-id": "129477",
"x-csrftoken": document.cookie.match(/csrftoken=([\w\d]+); /)[1] ?? '',
"x-ig-app-id": "936619743392459",
"x-ig-www-claim": "hmac.AR3F4jZAP9zLJfaCMqsFT-
I5N9rMUZnKkqqUNOxbRgxJ63jS",
"x-requested-with": "XMLHttpRequest"
},
"referrerPolicy": "strict-origin-when-cross-origin",
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "include"
});
const {native_location_data: {ranked: json}} = await res.json();
const medias = json.sections.filter(f => f.feed_type == 'media').map(m =>
m.layout_content.medias.map(e => e.media)).flat();
const dat = medias.map(med => ({ link: `https://instagram.com/p/$
{med.code}`, content: (med.caption?.text || '').trim() }));
if(json.more_available) {
const _next = await next(json.next_media_ids, json.next_max_id,
json.next_page)
return [...dat, ..._next];
}
return dat
}

async function next(nmid, nmax, np) {


const res = await
fetch("https://www.instagram.com/api/v1/locations/763807756/sections/", {
"headers": {
"accept": "/",
"accept-language": "en-US,en;q=0.9,id;q=0.8",
"content-type": "application/x-www-form-urlencoded",
"priority": "u=1, i",
"sec-ch-prefers-color-scheme": "dark",
"sec-ch-ua": "\"Not/A)Brand\";v=\"8\", \"Chromium\";v=\"126\"",
"sec-ch-ua-full-version-list":
"\"Not/A)Brand\";v=\"8.0.0.0\", \"Chromium\";v=\"126.0.6478.56\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-model": "\"\"",
"sec-ch-ua-platform": "\"Linux\"",
"sec-ch-ua-platform-version": "\"6.1.0\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-asbd-id": "129477",
"x-csrftoken": document.cookie.match(/csrftoken=([\w\d]+); /)[1] ??
'',
"x-ig-app-id": "936619743392459",
"x-ig-www-claim": "hmac.AR3F4jZAP9zLJfaCMqsFT-
I5N9rMUZnKkqqUNOxbRgxJ63jS",
"x-instagram-ajax": "1014685373",
"x-requested-with": "XMLHttpRequest"
},
"referrerPolicy": "strict-origin-when-cross-origin",
"body": `surface=grid&tab=ranked&max_id=$
{encodeURIComponent(nmax)}&next_media_ids=${encodeURIComponent('[' +
nmid.map(i =>"${i}").join(', ') + ']')}&page=${np}`,
"method": "POST",
"mode": "cors",
"credentials": "include"
});
const json = await res.json();
const medias = json.sections.filter(f => f.feed_type == 'media').map(m =>
m.layout_content.medias.map(e => e.media)).flat();
const dat = medias.map(med => ({ link: `https://instagram.com/p/$
{med.code}`, content: (med.caption?.text || '').trim() }));
return dat;
}
;(async () => {
document.body.innerHTML = '';
const result = await search(800636694);
document.body.innerHTML = '<table border="1">' + result.map(e =>
`<tr><td>${e.content}</td><td>${e.link}</td></tr>`).join('') + '</table>'
})();

You might also like