Get Instagram Posts Without any API

Spread the love

There is very simple way to pull instagram feeds from any account using “file_get_contents” method of PHP.

Here is the demo of the script in working condition.

<?php
    $myUserID = '50232398';
    $profileUrl = "https://instagram.com/graphql/query/?query_id=17888483320059182&id=".$myUserID."&first=20";
    
    $response = file_get_contents($iterationUrl);
    if ($response === false) {
        break;
    }
    $data = json_decode($response, true);
    if ($data === null) {
        break;
    }
    $media = $data['data']['user']['edge_owner_to_timeline_media'];
    $nodes = $media['edges']; 
    foreach ($nodes as $thispost) { 
	$post = $thispost['node'];
	$postId = $post['id'];
	$type = $post['__typename'];
	$link = 'https://www.instagram.com/p/'.$post['shortcode'];
	$picture = $post['display_url']; 
	$message = ($post['edge_media_to_caption']['edges'][0]['node']['text']) ? $post['edge_media_to_caption']['edges'][0]['node']['text'] : "";
	$thumbnail = $post['thumbnail_resources'][4]["src"];
	$created_time = date('Y-m-d H:i:s', $post['taken_at_timestamp']);
    } 
?>

Source can be download from here.