Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
882 views
in Technique[技术] by (71.8m points)

Instagram web api get: :ERR_BLOCKED_BY_RESPONSE

I created a script that extracts photos in the gallery of a certain profile… Using instagram-web-api

Unfortunately now it no longer works, instagram does not return the image of the media This is the mistake: ERR_BLOCKED_BY_RESPONSE

Instagram has changed it’s CORS policy recently? How I can fix?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The same issue was reported recently on https://github.com/restyler/instagram-php-scraper.

Instagram now sets cross-origin-resource-policy: same-origin if it doesn't like the "referer" which your browser sends to cdninstagram domain when loading image.

One of ways to mitigate this might be to create a simple image proxy which will work on your domain, download the image from instagram server to your server, and then output it to the browser.

Here is an example of CloudFlare image proxy:

https://gist.github.com/restyler/6c51e3ad20d7596e799d76e87cf93236

Not that efficient, but can be self-hosted, PHP implementation:

https://github.com/restyler/inwidget-proxified/blob/master/imgproxy.php

It might be a good idea to add additional caching layer on the proxy to reduce the amount of duplicate image requests to instagram cdn servers.

When you have your image proxy running, you just need to replace all instagram image srcs to the proxified versions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...