1

我正在尝试使用googleapiNode.js (YouTube API V3) 中的模块将视频上传到我的 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',
}

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

谢谢你!

4

1 回答 1

1

我找到了答案如果有人正在寻找它 - 片段应该是resource请求选项中对象的一部分

(我也转换fs.readFilefs.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);
        }
    });
};
于 2014-08-25T11:08:29.713 回答