How To Get Public Instagram Post JSON using JavaScript/PHP Without Access Token.

In this blog post, I will be explaining how to fetch data related to an Instagram public post using JavaScript or PHP without an access token.

In the first part i will be using the JavaScript to fetch the data and display it on a Webpage and in the second part, we will do it with PHP Procedural approach.

The First thing that is to be done is to get the URL of the post or the Post ID from Instagram. In my case, I am using Cristiano Ronaldo’s post to demonstrate this.

Here is the URL of Instagram post that i am using

to get the JSON of above post we need to add “?__a=1” at the end of the URL.

Now, it would look something like this.'

We will be using the above URL to get the JSON data of the current post.

To display the data on the webpage Using JavaScript, we will be using the Bootstrap card to display the details that we will fetch from the above URL.

The Source Code of this Bootstrap Card is:

<div class=”card” style=”width: 18rem;”>
<img class=”img img-responsive” id=”postImage” class=”card-img-top” alt=”…”>
<p>Username : <strong><span id=”instaUsername”></span></strong> </p>
<p>Name: <strong> <span id=”instaName”></span></strong></p>
<div class=”card-body”>
<p class=”card-text”>No of Likes | <strong><span id=”noLikes”></span></strong></p>
<p class=”card-text”> No Of Comments | <strong><span id=”noComments”></span></strong></p>


Code Screenshot

Here is the JavaScript code that fetches the data and displays it on the webpage.



.then(response => response.json())
.then(data => {
// Do something with your data

// Fetch Image
var imageUrl = data.graphql.shortcode_media.display_url;
document.getElementById(“postImage”).src= imageUrl;

// Fetch Username
var userName = data.graphql.shortcode_media.owner.username;

// Fetch Account Name
var accountName = data.graphql.shortcode_media.owner.full_name;

// Get Post Likes
var noLikes = data.graphql.shortcode_media.edge_media_preview_like.count;

// Get Post Comments
var noComments = data.graphql.shortcode_media.edge_media_preview_comment.count;




Now, below is the Code to implement same using PHP.


$json = file_get_contents(‘');

$obj = json_decode($json);

echo ‘ <img class=”img img-responsive” src=”’.$obj->graphql->shortcode_media->display_url.’” id=”postImage” class=”card-img-top” alt=”…”>

<p>Username : <strong><span id=”instaUsername”>’.$obj->graphql->shortcode_media->owner->username.’</span></strong> </p>

<p>Name: <strong> <span id=”instaName”>’.$obj->graphql->shortcode_media->owner->full_name.’</span></strong></p>

<div class=”card-body”>

<p class=”card-text”>No of Likes | <strong><span id=”noLikes”>’.$obj->graphql->shortcode_media->edge_media_preview_like->count.’</span></strong></p>

<p class=”card-text”> No Of Comments | <strong><span id=”noComments”>’.$obj->graphql->shortcode_media->edge_media_preview_comment->count.’</span></strong></p>



This explains how you will be able to fetch the details of Instagram Post (Public) using PHP or JavaScript.

Github Link: Click Here


Read on My Blog:

Design, Code and Data.