So I'm trying to pull some instagram images using the public API:
const url = `https://www.instagram.com/${username}/?__a=1`;
fetch(url)
.then(response => response.json())
.then(data => {
prepareImages(data['graphql']['user']['edge_owner_to_timeline_media']['edges'])
})
.catch(error => console.log(error));
This works perfectly fine 4 times out of 5. However, once in a while, I get an error saying:
Access to fetch at 'https://www.instagram.com/instagram/?__a=1' from origin 'https://test.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I have tried changing the mode to 'no-cors', but that just leads to an empty response. Do you guys think they just block the request sometimes to prevent spamming?