9

私は公式のGoogle API ノード クライアントである程度の前進を遂げましたが、動画ファイルを YouTube にアップする方法を考え出すのに少し行き詰まりました。

私はビデオを持っています:example.mp4

私はこのコードを持っています:

OAuth2Client = googleapis.OAuth2Client;               
var oauth2Client = new OAuth2Client('XXXXXX', 'XXXXXXX', 'http://callback_url');

googleapis.discover('youtube', 'v3').execute(function(err, client) {
  if (err) console.log(err);
  // I think the following is the bones of what I want to do
  client.youtube.videos.insert({}).execute(function(err, client) {
    if (err) console.log(err);
  }); 
});

挿入メソッドを使用してエラーが発生するだけで(パラメーターが渡されないと予想されました)、クライアントは初期化されて正常に戻ります。

ビデオ (スクリプトと同じディレクトリ内) を YouTube に渡す方法がわかりません。ポインタだけでも大歓迎です。

4

3 に答える 3

13

このコードはどうですか:

var googleapis = require('googleapis');

googleapis.discover('youtube', 'v3').execute(function(err, client) {

var metadata = {
    snippet: { title:'title', description: 'description'}, 
    status: { privacyStatus: 'private' }
};

client
    .youtube.videos.insert({ part: 'snippet,status'}, metadata)
    .withMedia('video/mp4', fs.readFileSync('user.flv'))
    .withAuthClient(auth)
    .execute(function(err, result) {
        if (err) console.log(err);
        else console.log(JSON.stringify(result, null, '  '));
    });
});
于 2014-01-26T04:20:54.613 に答える
1

このパッケージを使用してそれを行うことができます: https://github.com/h2non/youtube-video-api

于 2015-03-03T11:06:07.633 に答える