【问题标题】:Where are my uploaded videos from Youtube Data API?我从 Youtube Data API 上传的视频在哪里?
【发布时间】:2017-12-01 06:27:01
【问题描述】:

我正在关注有关使用 Node.Js (here is the link) 上传 Youtube 视频的教程,效果很好。唯一的问题是,完成脚本后,我找不到我上传的视频。这是我正在使用的脚本(正在上传的视频称为 video.mp4):

const Youtube = require("youtube-api");
const fs = require("fs");
const readJson = require('r-json');
const Lien = require("lien");
const Logger = require("bug-killer");
const opn = require("opn");
const prettyBytes = require("pretty-bytes");

const CREDENTIALS = readJson(`${__dirname}/credentials.json`);

// initialize Lien server
let server = new Lien({
    host: "localhost",
    port: 3000
});

let oauth = Youtube.authenticate({
    type: "oauth",
    client_id: CREDENTIALS.web.client_id,
    client_secret: CREDENTIALS.web.client_secret,
    redirect_url: CREDENTIALS.web.redirect_uris[0]
});

opn(oauth.generateAuthUrl({
    access_type: "offline",
    scope: ["https://www.googleapis.com/auth/youtube.upload"]
}));

server.addPage("/response", lien => {
    Logger.log("Trying to get the token using the following code: " + lien.query.code);
    oauth.getToken(lien.query.code, (err, tokens) =>{

        if (err){
            lien.lien(err, 400);
            return Logger.log(err);
        }
        Logger.log("Got the tokens");
        oauth.setCredentials(tokens);
        lien.end("The video is being uploaded.");
        var req = Youtube.videos.insert({
            resource:{
                snippet:{
                    title: "Testing Youtube API",
                    description: "testing the youtubes"
                },
                status: {privacyStatus: "private"}
            },
            part: "snippet, status",
            media: {
                body: fs.createReadStream("video.mp4")
            }
        },(err, data) => {
            console.log("Done." + data);
            process.exit();
        });
        setInterval(function(){
            Logger.log(`${prettyBytes(req.req.connection._bytesDispatched)} bytes uploaded.`);
        }, 250);
    });
});

我通过 console.log 得到正确的输出,告诉我视频已上传:

info  Trying to get the token using the following code: XXXXXXXXXX
info  Got the tokens
info  263 kB bytes uploaded.
info  384 kB bytes uploaded.
info  384 kB bytes uploaded.
info  384 kB bytes uploaded.
Done.

但登录我的 youtube 帐户后,我看不到那里的视频!我在我的 Google 仪表板上设置了两个项目:

【问题讨论】:

  • @JaromandaX 我认为这是一个合理的问题,我相信其他人也遇到过类似的问题,特别是考虑到我链接到的代码是 - 据我所知 - 唯一的示例代码它演示了通过 node.js 的 youtube-api 包上传到 Youtube 的视频。检查我的答案以尝试解决此问题。
  • 我知道这是一个合理的问题(如果我不认为它是,我会标记为关闭) - 第一部分是一个笑话,第二部分是我的诚实意见
  • @JaromandaX 明白了。花了一个晚上一遍又一遍地上传相同的玩具机器人视频后有点暴躁......

标签: javascript node.js video youtube


【解决方案1】:

希望这可以帮助下一个使用 Node.js 构建 Youtube Data API 连接的开发人员节省几个小时...假设您也是像我一样的 Youtube 新手。

这让我沮丧了一阵子,但最终一些视频开始出现在我的 YouTube 仪表板上,用于我的频道。我使用的视频是我从this website 下载的示例视频,这是问题的一部分。每次我上传视频时,它都会因违反服务条款而被立即删除,可能是出于版权或凭据原因。

但是,您可以通过点击视频管理器来查看实际实施是否有效。这些视频本身从未出现在我的上传视频列表中,但它们确实出现在视频管理器视图中:

This post 也描述了类似的问题。

所以有一些经验法则: (1) 找到您自己的视频并适当标记详细信息,以避免上传因服务条款而被删除 (2) 检查您的视频管理器,以更详细地查看您上传的视频,只需“上传”标签即可。

编辑:文章的作者也回复了我的评论,并提出了一个很好的建议,可以查看我的Creator Studio

【讨论】:

    猜你喜欢
    • 2012-03-10
    • 2021-01-12
    • 2020-12-19
    • 2012-04-10
    • 2021-10-07
    • 2021-07-09
    • 1970-01-01
    相关资源
    最近更新 更多