3

I downloaded and installed the google apis with npm install googleapis and now i'm trying to access the api in my node js file with this code:

var google = require('googleapis')
var youtube = google.youtube({version: 'v3', auth: API_KEY})

However, when I try to access the videos object, I always get back null. Apparently, the youtube object is corrupted because when I stringify it I get this back:

{"_options":{"auth":"*********"},"activities":{},"captions":{},"channelBanners":{},"channelSections":{},"channels":{},"commentThreads":{},"comments":{},"guideCategories":{},"i18nLanguages":{},"i18nRegions":{},"liveBroadcasts":{},"liveStreams":{},"playlistItems":{},"playlists":{},"search":{},"subscriptions":{},"thumbnails":{},"videoAbuseReportReasons":{},"videoCategories":{},"videos":{},"watermarks":{},"google":{"_options":{},"auth":{"_cachedCredential":null}}}

So all of the little "subobjects" are empty. How do I fix this?

SalmonKiller
  • 2,183
  • 4
  • 27
  • 56

3 Answers3

0

Did you check if the dependency is listed in your package.json file ? If not try npm install --save googleapis which directly adds it to your dependency list

0

There's nothing worrying in the fact that your youtube variable shows empty objects when stringified, because JSON representation of that object only contains properties that are primitive types. youtube.videos object contains only methods, which are ommited by JSON.stringify.

Try this:

var google = require('googleapis');
var youtube = google.youtube({version: 'v3', auth: API_KEY});
var queryOptions = {
    'part': 'id,snippet',
    'maxResults': 5,
    'id': 'dQw4w9WgXcQ,HL1UzIK-flA'
};
youtube.videos.list(queryOptions, function(err, data) {
    if(err) {
        console.error(err);
        return;
    }

    console.log(data);
});
jkondratowicz
  • 1,291
  • 15
  • 21
-2

For youtube api I use youtube-node and it works fine: https://github.com/nodenica/youtube-node

Rodrigo Reis
  • 1,891
  • 1
  • 11
  • 12