I'm trying to get json of instagram post. The url to fetch data:
$url = "https://www.instagram.com/p/" . $_GET['media'] . "/?__a=1";
When I'm get this url in browser - all fine, json returned. Btw browser not logged in to instagram. But when I use curl or file_get_contents($url); it return http code 302 with header 'location' to login page.
Code sample:
$url = "https://www.instagram.com/p/" . $_GET['media'] . "/?__a=1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json') );
$data = curl_exec($ch);
curl_close($ch);
var_dump($data);
Maybe curl options should be modified to look like browser.
Update
I have try same headers as in browser, include cookie, but no luck, seems this impossible. I have already written page using this hack, what stop working recently. Using API means rewrite everything as data in response is different.
