-
-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New policy? strict-origin-when-cross-origin #205
Comments
Refs to #204 Your pictures come from an old feed? (eg. saved in database)? |
Nope! But thats ok, it's not this API fault! I was able to "bypass" Instagram CORS by saving the image content into a file, then display the saved file instead the one recieved from api! Thanks and FU Facebook! |
Yeah, that's bad. Another solution could be to use an image proxy service : |
Just to confirm, there's no easy way around the CORS policy change, we either have to save locally or use a proxy? |
@samholguin I don't find a way to avoid CORS policy change (by changing pictures signatures maybe). |
i, particularly, am using
Use like: |
If anyone needs a WordPress solution:
|
I may add a method to save pictures directly in this package. Example : // previously, instanciate cachepool blabla
$api = new Api($cachePool);
$api->login($credentials->getLogin(), $credentials->getPassword());
$profile = $api->getProfile('twhiddleston');
foreach($profile->getMedias() as $media) {
$localMedia = $media->downloadTo('/path/to/your/storage/folder');
print_r($localMedia); // will return file name of media on your storage folder
} What do you think about? |
We can't use the src returned by the API as the src value to embed an image with an |
That's the CORS policy, you can't embedded the IG picture into your website in an But you can access to this picture with a direct link from a client (curl, wget or direct access from your browser). Another method could be to use an image proxy service (e.g. https://cloudinary.com/documentation/fetch_remote_images |
Thanks, I began to realize I was answering my own question as I was typing but went ahead and posted in case others had wondered the same. We decided to just save and serve the images locally (as others here have also suggested) and that seems to be working well. Likely a better scenario anyway as it will avoid running afoul of Facebook's usage limits. |
Good idea. I am not sure it will be useful in cases like mine when working with the likes of WordPress, but people can easily sort that as I did. |
i've same issue, for me this simple way can quick solve the problem in prod 😄 private function getImage($url, $ext, $host)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, urldecode($url));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'accept-encoding: gzip, deflate, br',
'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
'host: '.$host
));
$picture = curl_exec($ch);
curl_close($ch);
header('Content-type: image/'.$ext);
echo $picture;
} Just load image from your server side if possible 👍 |
PS: mime_content_type() will be use for local file, Not for remote file URL :) Thanks for the trick! |
this works perfectly, thanks |
thanks for the contributions... i hadn't even noticed, because the image was actually locally |
Awesome plugin thanks!!! I got this working– and converted the JPGs to webp as well
|
Very simply function to download URL content to your server: downloadURL($media->getThumbnailSrc(), $media->getId());
function downloadURL($url, $filename) {
$content = file_get_contents($url);
file_put_contents(__DIR__ ."/{$filename}.jpg", $content);
} |
@Nispeon Could you take a look at this enhancement please? Maybe create a method to download media on a targeted directory Thanks 👀 |
@Nispeon had a new helper in 6.8.0 version. You can now download picture directly with this package. Helper code : https://github.com/pgrimaud/instagram-user-feed/blob/master/src/Instagram/Utils/MediaDownloadHelper.php |
I know the issue is closed but I just wrapped up a library you can use to download and temporarily cache the media (and therefore not need to host it forever). It will either give you the cached URL back, or download the media before giving you the cached URL. Lifetimes and timestamps are stored per media item. https://github.com/FreshVine/expiring-media-cache Example:
|
Looks like facebook added a new CORS policy and you cant display the data directly anymore...
Is there any way to display the image into a
tag?
The text was updated successfully, but these errors were encountered: