Skip to content

Instantly share code, notes, and snippets.

@michaeldoye
Last active July 14, 2016 06:56
Show Gist options
  • Save michaeldoye/5df4214ee7a2e4629a303fb32dc8e5a3 to your computer and use it in GitHub Desktop.
Save michaeldoye/5df4214ee7a2e4629a303fb32dc8e5a3 to your computer and use it in GitHub Desktop.
FaceBook Comment names
jQuery(document).ready(function($) {
let _fulurl= 'https://graph.facebook.com/xxx/posts?since=1465516800&until=1468108800&access_token=xxx';
let _url = 'https://graph.facebook.com/v2.6';
let _token = 'xxx';
// Get all posts (recursively)
function get_posts(url) {
$.get(url, {}, {}, 'json').then(function(response) {
if (response.data) {
$.each(response.data, function(i, v) {
// Get comments for each post
get_comments(v.id);
});
}
// Repeat for each page
if (!response.paging) return;
get_posts(response.paging.next);
});
}
// Fetches the comments
function get_comments(id) {
$.get(_url+'/'+id+'/comments?access_token='+_token, {}, {}, 'json').then(function(response) {
if (response.data) {
render_results(response);
}
if (!response.paging) return;
$.get(response.paging.next, {}, render_results, 'json');
});
}
// Render the results (names of people who commented)
function render_results(response) {
if (response.data) {
$.each(response.data, function(i, v) {
$('body').append('<p>'+v.from.name+'</p>');
});
}
}
// Initiate
get_posts(_fulurl);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment