Problem: Instagram CORS Policy, I can't extract the data on my website

Markk7

Newbie
Feb 22, 2015
22
2
Hello everybody,
I have a website that needs to extract data from Instagram to show photos and descriptions of some influencers, calculate the percentage of engagement, etc. but since Instagram has integrated the CORS policy I have a hard time doing this.
For a while I fixed it by replacing the original link with "https: // images" + ~~ (Math.random () * 3333) + "-focus-opensocial.googleusercontent.com/gadgets/proxy?container=none&url=https : //www.instagram.com/ "but now this has stopped working too.
Anyone have any suggestions on how to fix this? Thank you
 
  • Cloudflare worker to bypass Instagram new cross-origin policy on images (ERR_BLOCKED_BY_RESPONSE).
  • Create new worker and put the code below into the worker code:
JavaScript:
async function handleRequest(request) {
let url = new URL(request.url)
if (!(request.headers.has('referer') && request.headers.get('referer').startsWith('https://yourwebsite.com/'))) {
    return new Response('Invalid referer. Please use your own Cloudflare workers.', {status: 400})
}
let newUrl = url.pathname.replace(/^\/+/, '').replace('https:/', 'https://') + url.search
let response = await fetch(newUrl.toString(), request)
response = new Response(response.body, response)
response.headers.set('cross-origin-resource-policy', 'cross-origin')
return response;
}

addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})

To get any data now use worker-url + target link.
 
  • Cloudflare worker to bypass Instagram new cross-origin policy on images (ERR_BLOCKED_BY_RESPONSE).
  • Create new worker and put the code below into the worker code:
To get any data now use worker-url + target link.
Thanks for the answer, I'm not familiar with cloudflare so I'm reading some guides to understand where to insert your code.
I will let you know if I have solved it.
 
I learned that my link was not wrong, however your method also solves the CORS problem anyway.

The problem is that Instagram has changed its html code, and the data is no longer present in JSON. I'll open a new thread on that since the new IG code appears to be fully encrypted.

Thanks for your help.
 
Back
Top
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features and essential functions on BlackHatWorld and other forums. These functions are unrelated to ads, such as internal links and images. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock