我想从用户Facebook墙上提取帖子.
以下代码段有效,但它永远不会终止:
var https = require('https');
facebookWall = function(user) {
var options = {
host: 'graph.facebook.com',
port: 443,
path: '/me/home?access_token=' + user.facebook_token + '&since=' + encodeURIComponent(user.facebook_timestamp),
method: 'GET',
headers: {
'Connection':'keep-alive'
}
};
var req = https.request(options)
.on('response', function(response) {
var body = '';
response.on('data', function(data) {
body += data;
try {
var wallPosts = JSON.parse(body);
console.log("user " + user.id + " has " + wallPosts.data.length + " new items on their wall");
}
catch (e) {
//console.log("waiting for more …Run Code Online (Sandbox Code Playgroud)