Reputation: 181
I'm using this code to get the last 8-10 post from an account:
$feed_instagram = file_get_contents('https://www.instagram.com/USERNAME/?__a=1');
$feed_instagram = json_decode($feed_instagram, true);
And it works like a charm in my development environment (local).
When I try to do the same in my staging development (AWS) it just returns a HTML with the Instagram logo.
Tried this other approach I saw on another post here:
$url = "https://www.instagram.com/USERNAME";
$html = file_get_contents($url);
$arr = explode('window._sharedData = ',$html);
$arr = explode(';</script>',$arr[1]);
$feed_instagram = json_decode($arr[0] , true);
And works locally aswell, but on the AWS environment it looks like it needs Login or something:
[entry_data] => Array
(
[LoginAndSignupPage] => Array
(
[0] => Array
(
[captcha] => Array
(
[enabled] =>
[key] =>
)
[gdpr_required] => 1
[tos_version] => eu
[username_hint] =>
)
)
)
Locally, in "entry_data" i get a "ProfilePage" object with all the info I need.
Any clue why this is happening? Thanks.
Upvotes: 3
Views: 1286
Reputation: 181
Solving this two months old question, it seems like Instagram / Facebook blocks certain services IPS (tested AWS and Digital Ocean). Since this project only needed to be running for two months, I ended up using a Raspberry Pi with a cron task.
Upvotes: 3