Skip to content Skip to sidebar Skip to footer

Cannot Read Results From Nodejs Request Result

I make a request towards FB graph api through node js' request: request({ url: 'https://graph.facebook.com/v2.6/' + userId + '?fields=first_name,last_name&access_token

Solution 1:

If the first call console.log('user data ' + data); returns:

"user data{"first_name":"A","last_name":"B"}"

And not:

"user data[object Object]"

It means, that the data object is a String, not an Object. If you want to use it as an Object and access it's fields, first parse it using:

var parsedData = JSON.parse(data);
console.log(parsedData.first_name); // Logs first_name now

Post a Comment for "Cannot Read Results From Nodejs Request Result"