-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
38 lines (36 loc) · 885 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var FB = require('fb');
var async = require('async')
var fs = require('fs')
var accessToken = ``;
FB.setAccessToken(accessToken);
// object xxxxxxxxx/comments
FB.api('00000000000/comments', 'GET', {
"limit": 500
}, function(res) {
if (!res || res.error) {
console.log(!res ? 'error occurred' : res.error);
return;
}
res = JSON.stringify(res);
let json = JSON.parse(res)
let data = "";
let p1 = new Promise((resolve, reject) => {
async.eachSeries(json.data, (row, callback) => {
console.log(row.message);
data = data + row.message + "\r\n"
setTimeout(function() {
callback()
}, 100);
}, function() {
resolve(data)
});
});
p1.then((data) => {
fs.writeFile("data.txt", '\ufeff' + data, {
encoding: 'utf8'
}, function(err) {
if (err) throw err;
console.log("SAVE!!");
});
})
});