Skip to content

Instantly share code, notes, and snippets.

@thedavedavies
Created April 3, 2019 09:44
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 thedavedavies/064dee311d3366032973e8fed6a3fd67 to your computer and use it in GitHub Desktop.
Save thedavedavies/064dee311d3366032973e8fed6a3fd67 to your computer and use it in GitHub Desktop.
// Based on: https://rudrastyh.com/instagram/get-photos-and-profile-info-pure-javascript.html
<div class="row row-insta"></div>
<script type="text/javascript">
const token = 'xxxxxx-xxxxxx-xxxxxx', // API Token Goes Here
num_photos = 6, // maximum 20
container = document.querySelector( '.row-insta' ),
scrElement = document.createElement( 'script' );
window.getResult = function( data ) {
for( x in data.data ){
const monthNames = ["January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"];
const ts = Number(data.data[x].created_time);
const milliseconds = ts * 1000;
const date = new Date(milliseconds);
const day = date.getDate();
container.innerHTML += `<div class="col-sm-2 col-4"><a href="${data.data[x].link}" target="_blank" rel="noopener noreferrer"><img src="${data.data[x].images.thumbnail.url}"></a><div class="insta-caption">Posted on: ${day} ${monthNames[date.getMonth()]}</div></div>`;
}
}
scrElement.setAttribute( 'src', `https://api.instagram.com/v1/users/self/media/recent?access_token=${token}&count=${num_photos}&callback=getResult` );
document.body.appendChild( scrElement );
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment