Advertisement
$(document).ready(function () { /* set a username from PHP */ var username = $("#instuser").text(); if ($("#instuser").length) { /* define variable to store the profile data */ var profile; /* define variable to store the images object/array */ var images; /* ajax request to self */ $.ajax({ url: window.location.protocol + "//" + window.location.host + "/instagram/", dataType: 'json', data: "username=" + username, success: function (result) { if (result.error) { $(".title").html("Unable to read/store .json data from local/remote site / code (" + result.error + ")"); } else { console.log(result); /* re-map the object to suitable variable-names */ profile = result['entry_data']['ProfilePage'][0]['user']; images = result['entry_data']['ProfilePage'][0]['user']['media']['nodes']; $("#image-insta").html(""); $("#username-insta").html("@" + profile.username + ""); $("#bio").html(profile.biography); //append the user full name to H1 // $("#name").html(profile.full_name); $("#bio").html(profile.biography); $("#followed_by").html(profile.followed_by.count); $(".instagram_site").attr({'href': 'https://instagram.com/' + profile.username}); // uncomment these to see the other properties available // //console.log(profile); //console.log(images); //counter image // var counter = 0; $(images).each(function () { // a new class needs to be added each 3:rd image // var row_start = ''; if (counter % 3 == 0) { row_start = ' rowstart'; } else { row_start = ''; } // use https // //append each instagram image to ol elem with id phinstagram-list// $("#phinstagram-list").append('
  • ' + this.likes.count + ' likes
  • '); counter++; }); } } }); } }) ;