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
const axios = require('axios'); | |
const { JSDOM } = require("jsdom"); | |
const fs = require("fs"); | |
(async () => { | |
try { | |
// Go from page 1 to 82 | |
for (let j = 1; j <= 82; j++) { |
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
// load font | |
var wfScript = document.createElement('script'); | |
wfScript.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js'; | |
document.head.appendChild(wfScript); | |
// apply font | |
setTimeout(() => { | |
WebFont.load({ | |
google: { | |
families: ['Roboto'] |
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
name: deploy-to-dev-droplet | |
on: | |
push: | |
branches: | |
- dev | |
jobs: | |
deploy-backend: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy backend |
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
# name of github action workflow | |
name: deploy-to-dev-droplet | |
on: | |
push: | |
branches: | |
- dev # this script will run when pushed to "dev" branch | |
jobs: | |
deploy-frontend: | |
runs-on: ubuntu-latest #using latest ubuntu to build application | |
steps: |
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
import cron from 'node-cron'; | |
import instaCacheCron from "./crons/instaCache.cron"; | |
// run immediately after server starts | |
instaCacheCron(); | |
// update instaPhotos Cache every 3 hours | |
cron.schedule('0 0 */3 * * *', async () => { | |
// this method fetches updated Insta images and saves to DB. | |
await instaCacheCron(); |
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
try { | |
let instaAccessToken = "XXXXXX"; // get from DB | |
let resp = await axios.get(`https://graph.instagram.com/me/media?fields=media_type,permalink,media_url&access_token=${instaAccessToken}`); | |
resp = resp.data; | |
let instaPhotos = resp.data.filter(d => d.media_type === "IMAGE").map(d => d.media_url); | |
// Got insta photos | |
} catch (e) { | |
console.log(e.response.data.error); | |
} |
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
try { | |
let oldAccessToken = "XXXXX"; // get from DB | |
let resp = await axios.get(`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${oldAccessToken}`) | |
if (resp.data.access_token) { | |
let newAccessToken = resp.data.access_token; | |
// save newAccessToken to DB | |
} | |
} catch (e) { | |
console.log("Error=====", e.response.data); | |
} |
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
import cron from 'node-cron'; | |
import instaRefreshCron from "./crons/instaRefresh.cron"; | |
// run immediately after server starts | |
instaRefreshCron(); | |
// refresh instaAccessToken eg: weekly(every Sat) | |
cron.schedule('* * * * * 7', async () => { | |
await instaRefreshCron(); | |
}); |
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
try { | |
let resp = await axios.get(`https://graph.instagram.com/access_token?grant_type=ig_exchange_token&client_secret=${process.env.INSTA_APP_SECRET}&access_token=${accessToken}`) | |
accessToken = resp.data.access_token; | |
// save accessToken to Database | |
} catch (e) { | |
console.log("Error=====", e.data); | |
} |
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
// data from frontend | |
let code = req.body.code; | |
let redirectUri = req.body.redirectUri; | |
let accessToken = null; | |
try { | |
// send form based request to Instagram API | |
let result = await request.post({ | |
url: 'https://api.instagram.com/oauth/access_token', |
NewerOlder