【问题标题】:Set YouTube video title when uploading with Node.js (googleapi module v1.0)使用 Node.js 上传时设置 YouTube 视频标题(googleapi 模块 v1.0)
【发布时间】:2014-10-18 01:29:37
【问题描述】:

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

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

这是我的代码:

//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',
}

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

谢谢!

【问题讨论】:

    标签: node.js upload youtube youtube-api google-api-nodejs-client


    【解决方案1】:

    我找到了答案 万一有人在找它—— sn-p 应该是请求选项中resource 对象的一部分

    (我也将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);
            }
        });
    };
    

    【讨论】:

      猜你喜欢
      • 2021-05-28
      • 2013-09-19
      • 2016-06-03
      • 1970-01-01
      • 1970-01-01
      • 2013-10-08
      • 2022-08-17
      • 2018-01-30
      • 2012-06-07
      相关资源
      最近更新 更多