Guest User

Untitled

a guest
Jan 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. const express = require('express');
  2. const router = express.Router();
  3. const axios = require('axios');
  4.  
  5. /* GET home page. */
  6. router.get('/', (req, res, next)=> {
  7. let instaPost;
  8.  
  9. getLatest(callback => {
  10. instaPost = callback;
  11. console.log(instaPost);
  12.  
  13. });
  14.  
  15. res.render('index', {
  16. title: 'Home',
  17. insta: instaPost
  18. });
  19. });
  20.  
  21. function getLatest(callback) {
  22. axios.get('https://api.instagram.com/v1/users/self/media/recent/?access_token=xxx&count=1')
  23. .then(response => {
  24. callback((response.data.data[0].link));
  25. })
  26. .catch(error => {
  27. callback(error);
  28. });
  29.  
  30. }
  31.  
  32.  
  33.  
  34. module.exports = router;
Add Comment
Please, Sign In to add comment