gpt4 book ai didi

node.js - 使用 Node.js 上传时设置 YouTube 视频标题(googleapi 模块 v1.0)

转载 作者:太空宇宙 更新时间:2023-11-04 01:03:04 26 4
gpt4 key购买 nike

我正在尝试使用 Node.js (YouTube API V3) 中的 googleapi 模块将视频上传到我的 YouTube channel

视频上传正常 - 我只是找不到如何将标题和描述传递给上传命令。

这是我的代码:

//Authorization stuff above

fs.readFile('./youtube_videos/in.avi', function(err, content){
if(err){
console.log('read file error: '+err);
} else {
yt.videos.insert({
part: 'status,snippet',
autoLevels: true,
media: {
body: content
}
}, function(error, data){
if(error){
console.log('error: '+error);
} else {
console.log('https://www.youtube.com/watch?v='+data.id+"\r\n\r\n");
console.log(data);
}
});
}
})

我知道如何传递一些snippet对象,例如

snippet: {
title: 'test upload2',
description: 'My description2',
}

但我找不到它应该在哪里 - 我尝试了所有(几乎)可能的组合

谢谢!

最佳答案

我找到了答案万一有人正在寻找它 -该代码段应该是请求选项中的资源对象的一部分

(我还将 fs.readFile 转换为 fs.createReadStream)

function uploadToYoutube(video_file, title, description,tokens, callback){
var google = require("googleapis"),
yt = google.youtube('v3');

var oauth2Client = new google.auth.OAuth2(clientId, appSecret, redirectUrl);
oauth2Client.setCredentials(tokens);
google.options({auth: oauth2Client});

return yt.videos.insert({
part: 'status,snippet',
resource: {
snippet: {
title: title,
description: description
},
status: {
privacyStatus: 'private' //if you want the video to be private
}
},
media: {
body: fs.createReadStream(video_file)
}
}, function(error, data){
if(error){
callback(error, null);
} else {
callback(null, data.id);
}
});
};

关于node.js - 使用 Node.js 上传时设置 YouTube 视频标题(googleapi 模块 v1.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25476739/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com