Created
April 3, 2019 09:44
-
-
Save thedavedavies/064dee311d3366032973e8fed6a3fd67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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