【问题标题】:Node JS - Youtube API Is BlankNode JS - Youtube API 是空白的
【发布时间】:2016-06-02 13:05:48
【问题描述】:

我使用npm install googleapis 下载并安装了google api,现在我正在尝试使用以下代码访问我的node js 文件中的api:

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

但是,当我尝试访问视频对象时,我总是返回 null。显然,youtube 对象已损坏,因为当我对其进行字符串化时,我得到了这个:

{"_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}}}

所以所有的小“子对象”都是空的。我该如何解决这个问题?

【问题讨论】:

  • 更新:以这种方式所有的api都是空的。我试过urlshortener,同样的问题仍然存在。

标签: javascript node.js youtube youtube-data-api google-api-nodejs-client


【解决方案1】:

您的youtube 变量在字符串化时会显示空对象这一事实并不令人担忧,因为该对象的 JSON 表示仅包含原始类型的属性。 youtube.videos 对象只包含被JSON.stringify 省略的方法。

试试这个:

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);
});

【讨论】:

    【解决方案2】:

    对于 youtube api,我使用 youtube-node,它工作正常:https://github.com/nodenica/youtube-node

    【讨论】:

      【解决方案3】:

      您是否检查过您的 package.json 文件中是否列出了依赖项?如果没有尝试 npm install --save googleapis 直接将其添加到您的依赖项列表中

      【讨论】:

        猜你喜欢
        • 2013-09-09
        • 2019-11-08
        • 2015-01-13
        • 1970-01-01
        • 2016-05-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-23
        相关资源
        最近更新 更多