Created
November 17, 2016 00:46
-
-
Save CestDiego/7678346a9f44cf992b6f017e4c52c9eb to your computer and use it in GitHub Desktop.
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
const Promise = require('bluebird'); | |
const request = require('request-promise'); | |
const writeFile = Promise.promisify(require("fs").writeFile); | |
const ACCESS_TOKEN = "EAACEdEose0cBALbEdSecEYjBs0nEcqW2gKJLvpMOqRKWRLreYh1ROUSjHg8M6893BBljot9DmNRm3Vnue2lP7c0BjdRvFY0XRY0UzDc9gsw8RUpHngJBuRJTgZBohYRZAhvvTH3nxxIwyoZC6NWIDaqxkma7nuHx4BytwsOBAZDZD"; | |
const BASE_URL = `https://graph.facebook.com/v2.8/me/feed?access_token=${ACCESS_TOKEN}&limit=300&until=1453664307`; | |
function getNextPromise(url) { | |
return request({ | |
url, | |
json: true | |
}) | |
} | |
let posts = []; | |
let corpus = ""; | |
request({ url: BASE_URL, json: true }) | |
.then(function parseResult(body) { | |
if (body.error) { | |
console.log('Fatal Error'); | |
console.log(body.error); | |
return Promise.resolve() | |
} | |
Array.prototype.push.apply(posts, body.data) | |
console.log(`Posts Collected so far: ${posts.length}. Got ${body.data.length} posts this time`); | |
if(body.paging && body.paging.next) { | |
return getNextPromise(body.paging.next).then(parseResult) | |
} | |
else { | |
return Promise.resolve() | |
} | |
}) | |
.then(() => { | |
console.log(`Finished... | |
Writing to file now`); | |
return writeFile('diego-posts.json', JSON.stringify({ posts }, null, 4)) | |
}) | |
.then(() => { | |
console.log('---------'); | |
console.log(corpus); | |
}) | |
.then(() => { | |
console.log(`Posts Saved > diego-posts.json | |
kthxbai`); | |
return Promise.resolve(posts) | |
}) | |
.catch(err => { | |
if (err.error) console.log(err.error); | |
else console.log(err); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment