php - Get Instagram feed with Curl

one text

Solution:

This seems wrong:

$url = "https://www.instagram.com/'.$username.'/?__a=1";

Try this:

$url = "https://www.instagram.com/{$username}/?__a=1";

It is very possible that Instagram is blocking such requests via curl/cli/php, or it would Forward your request to the Login page..

Also in your PHP curl request you do not do any sanity checks.. like, for example what does Curl returns as HTTP code:

"Curl returned: ".curl_getinfo($ch, CURLINFO_HTTP_CODE);

check curl_getinfo

You also do not check if JSON did not error out via json_last_error . Those are basics in troubleshooting..

Once you know what each of those returns, you will be able to better troubleshoot your code.

Source