我想将视频从服务器上传到youtube。 我创建了一个服务帐户到auth,
var path = "720_final.mov"
// var key = readJson(`${__dirname}/secret.json`);
var google = require('googleapis');
var youTube = google.youtube('v3');
var authClient = new google.auth.JWT(
"xxxx@yyyyyyy.gserviceaccount.com",
"secret.p12",
null,
['https://www.googleapis.com/auth/youtube','https://www.googleapis.com/auth/youtube.upload'],
null
);
authClient.authorize(function(err, tokens) {
if (err) {
console.log(err);
return;
}
authClient.setCredentials(tokens);
var req = Youtube.videos.insert({
auth: authClient,
resource: {
// Video title and description
snippet: {
title: "Testing YoutTube API NodeJS module"
, description: "Test video upload via YouTube API"
}
// I don't want to spam my subscribers
, status: {
privacyStatus: "public"
}
}
// This is for the callback function
, part: "snippet,status"
// Create the readable stream to upload the video
, media: {
body: fs.createReadStream(path)
}
}, (err, data) => {
console.log(err)
console.log(data)
process.exit();
});
我的文件720_final.mov
的大小为33Mb。
上传到34.6Mb时似乎上传无法找到用户上传的频道??
但是,当从Oauth2使用令牌生成器时,上传成功,例如使用誓言2 https://github.com/IonicaBizau/youtube-api/blob/master/example/index.js
任何人都可以给我一个解决方案或关键字来解决这个问题吗?