如何使用javascript或Node.js上传指定帐户的Youtube视频

时间:2016-12-13 11:06:49

标签: javascript node.js video youtube youtube-api

我正在构建一个需要通过代码在Youtube上传视频的网络应用程序。我知道我可以使用以下按钮登录Google:

 <google-sign-in-button button-id="uniqueid" options="options"></google-sign-in-button>

与:

<meta name="google-signin-client_id" content="CLIENT_ID.apps.googleusercontent.com">

<script src="https://apis.google.com/js/platform.js" async defer></script>

(如https://developers.google.com/identity/sign-in/web/sign-in中所述),然后上传视频(如https://developers.google.com/youtube/v3/code_samples/javascript#authorizing_requests中所述)。

上下文是:

  • 我的应用程序中有一个视频管理器。
  • 管理员可能会将这些视频上传到Youtube频道。

问题是:

  • 管理员可能在使用该应用程序时登录了自己的Google帐户。
  • 必须将视频上传到与管理员不同的帐户。

问题:

有没有办法在代码中指定特定的Youtube帐户,以便将视频上传到该帐户的Youtube频道?

我不知道使用javascript或Nodejs解决这个问题是否更好,所以欢迎任何提示。

编辑:

根据KEndi的回答,我正在使用此调用来执行插入功能:

Youtube.videos.insert({
  resource: {
    snippet: {
      title: "Testing YoutTube API NodeJS module",
      description: "Test video upload via YouTube API"
    },
    status: {
      privacyStatus: "private"
    }
  },
  part: "snippet,status",
  media: {
    body: fs.createReadStream("video.mp4")
  },
  onBehalfOfContentOwner: CONTENT_OWNER_ID,
  onBehalfOfContentOwnerChannel: CONTENT_OWNER_CHANNEL
}, (err, data) => {
  if(err) { return lien.end(err, 400);}
  lien.end(data);
});

然而,我收到此错误:

  

错误:找不到指定的内容所有者帐户。       在Request._callback(...)

当我通过此链接尝试API时: https://developers.google.com/youtube/v3/docs/videos/list?hl=es-419 指定“onBehalfOfContentOwner”参数,我得到的响应是:

{  "error": {   "errors": [    {
    "domain": "youtube.parameter",
    "reason": "contentOwnerAccountNotFound",
    "message": "The specified content owner account was not found.",
    "locationType": "parameter",
    "location": "onBehalfOfContentOwner"    }   ],   "code": 404,   "message": "The specified content owner account was not found."  } }

0 个答案:

没有答案