I am making a request to the facebook api to get a list of friends. When I make the request through node.js, my request is always truncated. Does anyone understand why the response is being truncated?
Here is the code of my function:
var loadFriends;
loadFriends = function(access_token, callback) 开发者_C百科{
var https, options, start;
https = require('https');
start = new Date();
options = {
host: 'graph.facebook.com',
port: 443,
path: '/me/friends?access_token=' + access_token
};
return https.get(options, function(res) {
console.log("Request took:", new Date() - start, "ms");
res.setEncoding("utf8");
return res.on("data", function(responseData) {
var data;
console.log(responseData);
data = JSON.parse(responseData);
return callback(data);
});
});
};
The res.on('data')
event will happen multiple times as chunks of data arrives; you need to concatenate this together to get the whole response.
http://nodejs.org/docs/v0.4.0/api/http.html#event_data_
精彩评论