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) {
var https, options, start;
https = require('https');
start = new Date();
options = {
host: 'graph.facebook',
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);
});
});
};
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) {
var https, options, start;
https = require('https');
start = new Date();
options = {
host: 'graph.facebook.',
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);
});
});
};
Share
Improve this question
edited Aug 2, 2011 at 5:27
Osei Bonsu
asked Aug 1, 2011 at 2:45
Osei BonsuOsei Bonsu
1071 silver badge10 bronze badges
2
- Please tag this with the language or framework you're using, as this is not JavaScript/node.js. – Dan Grossman Commented Aug 1, 2011 at 2:49
- I converted it from coffeescript to javascript and tagged it appropriately – Osei Bonsu Commented Aug 1, 2011 at 2:54
1 Answer
Reset to default 7The 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/docs/v0.4.0/api/http.html#event_data_