Skip to content

Instantly share code, notes, and snippets.

@toanalien
Last active March 24, 2017 12:21
Show Gist options
  • Select an option

  • Save toanalien/50aab2386bdfe2d30bea145f8f49d79d to your computer and use it in GitHub Desktop.

Select an option

Save toanalien/50aab2386bdfe2d30bea145f8f49d79d to your computer and use it in GitHub Desktop.
query all post from timeline
// prtsc = http://i.imgur.com/slXDaAn.png
var request = require('request');
var INTERVAL=864000;
var TOKEN='';
var USER_ID='';
// privacy_setting='286958161406148' # only me
var API_ENDPOINT = 'https://graph.facebook.com/v2.8/';
var from = '2012.01.01';
var to = new Date();
from = parseInt((new Date(from).getTime()/1000).toFixed(0));
to = parseInt((new Date().getTime()/1000).toFixed(0));
function getMe(token, cb) {
qs = {access_token: token};
request.get({url:API_ENDPOINT + '/me', qs: qs, json:true }, function(e, r, user) {
if (e) return cb(e);
if (r.statusCode != 200) return cb(r);
return cb(null, user);
});
}
function getUserPost(user, from, to) {
if (!to) {
// console.log('from ' + from);
to = from - INTERVAL;
qs = {access_token: TOKEN, since: to.toString(), until: from.toString(), limit: 1000}
// console.log(qs);
request.get({url:API_ENDPOINT + '/' + user.id +'/posts/', qs:qs, json:true}, function(e,r,posts) {
// console.log(e);
// console.log(r.statusCode);
if (e) return console.log(e);
if (r.statusCode!=200) return console.log(r);
// console.log(posts);
if (posts) posts = posts['data'];
if (posts.length == 0) return console.log('end of timeline');
posts.forEach(function(post,index){
if (post['story']) console.log(+ "\t" + post['id'] + "\t" +post['story']);
else console.log(+ "\t" + post['id'] + "\t" +post['message']);
});
getUserPost(user, to, null);
});
}
}
getMe(TOKEN, function(error, user) {
getUserPost(user, to, null);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment