Created
March 10, 2019 00:00
-
-
Save bouiboui/443b6f1811bf5f26663d7b1894dcb1c2 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
const FB = require('fb'); | |
FB.setAccessToken(process.env.FB_ACCESS_TOKEN); | |
async function fetchNextLikes(after) { | |
const url = 'me/likes?limit=100' + (after ? '&after=' + after : ''); | |
const response = await FB.api(url); | |
return [ | |
response.data.map(like => like.name), | |
response.paging && response.paging.cursors.after | |
]; | |
} | |
async function fetchFacebookLikes() { | |
let allLikes = []; | |
let isComplete = false; | |
let finalAfter = null; | |
while (!isComplete) { | |
const [nextLikes, after] = await fetchNextLikes(finalAfter); | |
allLikes = allLikes.concat(nextLikes); | |
finalAfter = after; | |
isComplete = nextLikes.length < 1; | |
console.log('Fetched ' + nextLikes.length + ' likes'); | |
} | |
return allLikes; | |
} | |
module.exports = fetchFacebookLikes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment