无法看到通过youtube-api上传的视频

时间:2017-12-12 23:16:45

标签: node.js youtube-api youtube-data-api

代码没有给出任何错误,但在youtube页面上没有任何内容。令牌是好的,我可以看到日志说它已经完成但在youtube上没有。 在youtube上显示视频需要多长时间?

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

// I downloaded the file from OAuth2 -> Download JSON
const CREDENTIALS = readJson(`${__dirname}/credentials.json`);

// Authenticate
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]
});

//the token obtained with getToken.js script
var tokens = readJson(`${__dirname}/tokens.json`);

//set the token
oauth.setCredentials(tokens);

var req = Youtube.videos.insert({
  resource: {
    snippet: {
      title: "Testing",
      description: "Test video upload via YouTube API"
    },
    status: {
      privacyStatus: "public"
    }
  },
  part: "snippet,status",
  media: {
    body: fs.createReadStream("video.mp4")
  }
}, (err, data) => {
  console.log("Done.");
  process.exit();
});

setInterval(function() {
  Logger.log(`${prettyBytes(req.req.connection._bytesDispatched)} bytes uploaded.`);
}, 250);

1 个答案:

答案 0 :(得分:1)

已解决,您必须为您的Google应用启用youtube Api v3。愚蠢的问题。