2017-06-28 28 views
2

我正在使用Node.Js(here is the link)上传Youtube视频的教程,它效果很好。唯一的问题是,在完成脚本后,我找不到我上传的视频。下面是我使用的脚本(被上传视频被称为video.mp4):我从Youtube Data API上传的视频在哪里?

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控制板上:enter image description here

+0

@JaromandaX我认为这是一个合法的问题,我相信其他人也会遇到类似的问题,尤其是考虑到我链接的代码是 - 据我所知 - 唯一示例代码演示视频上传通过node.js的'youtube-api'软件包加入Youtube。请检查我的答案,以解决此问题。 –

+0

我知道这是一个合法的问题(如果我不这么认为的话,我已经将其标记为关闭) - 第一部分是一个笑话,第二部分是我的一个诚实的意见 –

+0

@JaromandaX明白了。花了一晚上来重复上传相同的玩具机器人视频之后,稍微有些胡思乱想...... –

回答

3

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

这让我感到沮丧了一段时间,但最终一些视频开始在我的频道的YouTube控制面板上弹出。我使用的视频是从this website下载的示例视频,这是问题的一部分。每次我上传视频时,都会因违反服务条款而迅速将其删除,这可能是出于版权或凭证原因。

但是,您可以通过单击您的视频管理器来查看实际实施是否奏效。视频本身从未将其添加到我上传的视频列表中,但它们在视频管理器视图中显示:enter image description here

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

拇指那么一些规则: (1)找到自己的视频和标签适当地细节,以避免上传服务 的条款被删除(2)检查您的视频管理器为您的视频更详细的视图上传简单的“上传”标签。

编辑:文章的作者也回应了我的评论,并提供了一个很好的建议,看看我的Creator Studio