I have the following request call in my node.js app
request({ url:chanURL, qs:chanProperties}, function(err, response, body) {
if(err) { console.log(err); return; }
body = JSON.parse(body);
(function (body) {
Object.keys(body.items).forEach(function(item) {
pid = item.contentDetails.relatedPlaylists.uploads;
console.log(pid);
})
})();
})
And, I'm getting TypeError: Cannot read property 'items' of undefined
while processing the response.
The JSON object that I'm trying to work with is
{ kind: 'youtube#channelListResponse',
etag: '"0KG1mRN7bm3nResDPKHQZpg5-do/B7stMlWJTBpmW2q34yWKIzz8fF8"',
pageInfo: { totalResults: 1, resultsPerPage: 1 },
items:
[ { kind: 'youtube#channel',
etag: '"0KG1mRN7bm3nResDPKHQZpg5-do/vV2FFZUI5inz53NuQDJMTs3tdQk"',
id: 'UCwy6X3JB24VTsDFqMwdO5Jg',
contentDetails: [Object] } ] }
Why does it say items is undefined?
And I also would like to know if I want to execute the function within this request wrapper, I need to wrap it inside the parenthesis like I did? I did get syntax error without the parenthesis.