Skip to content

Instantly share code, notes, and snippets.

@jordanhudgens
Created August 7, 2014 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordanhudgens/d4f4a9e6c5744886ad49 to your computer and use it in GitHub Desktop.
Save jordanhudgens/d4f4a9e6c5744886ad49 to your computer and use it in GitHub Desktop.
Instagram Follower Counter
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function() {
$.ajax({
type: "GET",
dataType: "jsonp",
cache: true,
error: function(data) { console.log(data); },
url: "https://api.instagram.com/v1/users/361586616/?access_token=20271803.f59def8.dfd7d830c0794ee380b194d4423a889a",
success: function(data) {
var ig_count = data.data.counts.followed_by.toString();
ig_count = add_commas(ig_count);
$(".instagram_count").html(ig_count);
}
});
function add_commas(number) {
if (number.length > 3) {
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : '');
for (i=0 ; i < Math.floor(number.length / 3); i++) {
if ((mod == 0) && (i == 0)) {
output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
} else {
output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
}
return (output);
} else {
return number;
}
}
});
</script>
<span class="instagram_count"> </span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment