Skip to content

Instantly share code, notes, and snippets.

@jsakhil
Last active July 26, 2021 14:06
Show Gist options
  • Save jsakhil/7777b618dc5a3efdd7c6ebfa5eaa4fee to your computer and use it in GitHub Desktop.
Save jsakhil/7777b618dc5a3efdd7c6ebfa5eaa4fee to your computer and use it in GitHub Desktop.
Live Instagram Feed - Instagram API that fetches User Profile, Followers, Following, Images, Posts, Likes , Shares
$(document).ready(function(){
$.ajax({
url:"https://www.instagram.com/{username}/channel/?__a=1",
type:'get',
success:function(response){
posts = response.graphql.user.edge_owner_to_timeline_media.edges;
posts_html = '';
for(var i=0;i<8;i++){
url = posts[i].node.display_url;
post_shortcode = posts[i].node.shortcode;
caption = posts[i].node.accessibility_caption;
posts_html += '<a href="https://www.instagram.com/p/'+post_shortcode+'/" target="_blank">';
posts_html += '<img class="img-fluid" src="'+url+'" alt="'+caption+'">';
posts_html += '</a>';
}
$(".insta_wrapper").html(posts_html);
}
});
})
$(document).ready(function(){
$.ajax({
url:"https://graph.instagram.com/<USER-ID>/media?fields=id,media_url,timestamp&access_token=<ACCESS-TOCKEN>",
type:'get',
success:function(response){
posts = response.data;
posts_html = '';
for(var i=0;i<9;i++){
if(posts[i].media_type == 'IMAGE'){
url = posts[i].media_url;
caption = posts[i].caption;
permalink = posts[i].permalink;
posts_html += '<a href="'+permalink+'" target="_blank">';
posts_html += '<img class="img-fluid" src="'+url+'" alt="'+caption+'">';
posts_html += '</a>';
}
}
$(".insta_wrapper").html(posts_html);
}
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment