Last active
June 5, 2018 18:17
-
-
Save nabrown/10d1f53b1978e9adf6ad6c92ea176bfa to your computer and use it in GitHub Desktop.
Instagram Gallery Vue javascript
This file contains hidden or 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
var app = new Vue({ | |
el: '#app', | |
data: { | |
access_token: "your access token here", | |
url: "https://api.instagram.com/v1/users/self/media/recent/", | |
username: "", | |
grams: [], | |
next_url: "", | |
error: false | |
}, | |
computed: { | |
instapage() { | |
return 'https://www.instagram.com/' + this.username | |
} | |
}, | |
methods: { | |
getGrams() { | |
axios.get(this.url + "?access_token=" + this.access_token) | |
.then(({data}) => { | |
this.grams = data.data | |
this.username = data.data[0].user.username | |
this.next_url = data.pagination.next_url | |
}) | |
.catch(function (error) { | |
console.log(error) | |
this.error = true | |
}); | |
}, | |
getMoreGrams(){ | |
axios.get(this.next_url) | |
.then(({data}) => { | |
this.grams = this.grams.concat(data.data) | |
this.next_url = data.pagination.next_url | |
}) | |
.catch(function (error) { | |
console.log(error) | |
this.error = true | |
}); | |
} | |
}, | |
created() { | |
this.getGrams(); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment