0% found this document useful (0 votes)
59 views3 pages

Instagram API Media Fetching Code

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)
59 views3 pages

Instagram API Media Fetching Code

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

async function search(loc_id) {

const res = await


fetch(`[Link]
{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=\"[Link]\", \"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": [Link](/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 [Link]();
const medias = [Link](f => f.feed_type == 'media').map(m =>
m.layout_content.[Link](e => [Link])).flat();
const dat = [Link](med => ({ link: `[Link]
{[Link]}`, content: ([Link]?.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("[Link] {
"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=\"[Link]\", \"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": [Link](/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('[' +
[Link](i =>"${i}").join(', ') + ']')}&page=${np}`,
"method": "POST",
"mode": "cors",
"credentials": "include"
});
const json = await [Link]();
const medias = [Link](f => f.feed_type == 'media').map(m =>
m.layout_content.[Link](e => [Link])).flat();
const dat = [Link](med => ({ link: `[Link]
{[Link]}`, content: ([Link]?.text || '').trim() }));
return dat;
}
;(async () => {
[Link] = '';
const result = await search(800636694);
[Link] = '<table border="1">' + [Link](e =>
`<tr><td>${[Link]}</td><td>${[Link]}</td></tr>`).join('') + '</table>'
})();

You might also like