我被分配创建一个节点js应用程序,该应用程序提供给一些需要提交视频的受信任的人。预算真的很小,他们没有钱租用云存储。
现在我想知道是否可以生成某种密钥并将视频从设备上传到单个 youtube 频道。我搜索了文档,但找不到相关内容。
用户是内部的和受信任的,应用程序不可能掌握在其他人手中。
这可能吗?如果没有,什么是好的选择?
谢谢缺口
在google-api-nodejs-client repo中,这里有一个YouTube视频上传代码的例子,这里有一个示例文档
它使用用于将视频上传到YouTube的Youtube插入API,并设置视频的元数据
下面是一个最小的功能示例(在本例中需要手动设置授权代码(:
var google = require('googleapis');
var util = require('util');
var fs = require('fs');
var http = require('http');
var spawn = require('child_process').spawn;
var querystring = require('querystring');
var url = require('url');
var OAuth2 = google.auth.OAuth2;
var FILENAME = '/home/user/test.mp4';
// get these from https://console.developers.google.com/apis/credentials (don't forget to activate Youtube API)
var YOUR_CLIENT_ID = "XXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com";
var YOUR_CLIENT_SECRET = "XXXXX-XXXXXXXXXXXXXXXXXX";
var YOUR_REDIRECT_URL = "https://your-domain/redirect";
var oauth2Client = new OAuth2(
YOUR_CLIENT_ID,
YOUR_CLIENT_SECRET,
YOUR_REDIRECT_URL
);
// initialize the Youtube API library
var youtube = google.youtube({
version: 'v3',
auth: oauth2Client
});
// very basic example of uploading a video to youtube
function uploadVideo() {
var req = youtube.videos.insert({
part: 'id,snippet,status',
notifySubscribers: false,
resource: {
snippet: {
title: 'Node.js YouTube Upload Test',
description: 'Testing YouTube upload via Google APIs Node.js Client'
},
status: {
privacyStatus: 'private'
}
},
media: {
body: fs.createReadStream(FILENAME)
}
}, function(err, data) {
if (err) {
console.error('Error: ' + err);
}
if (data) {
console.log(util.inspect(data, false, null));
}
process.exit();
});
var fileSize = fs.statSync(FILENAME).size;
// show some progress
var id = setInterval(function() {
var uploadedBytes = req.req.connection._bytesDispatched;
var uploadedMBytes = uploadedBytes / 1000000;
var progress = uploadedBytes > fileSize ? 100 : (uploadedBytes / fileSize) * 100;
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(uploadedMBytes.toFixed(2) + ' MBs uploaded. ' +
progress.toFixed(2) + '% completed.');
if (progress === 100) {
process.stdout.write('nDone uploading, waiting for response...n');
clearInterval(id);
}
}, 250);
}
var scopes = [
'https://www.googleapis.com/auth/youtube.upload',
'https://www.googleapis.com/auth/youtube'
];
var authorizeUrl = oauth2Client.generateAuthUrl({
access_type: 'offline',
scope: scopes.join(' ')
});
console.log("go to " + authorizeUrl + " to get authorization code");
var AUTHORIZATION_CODE = "X/XXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXX";
oauth2Client.getToken(AUTHORIZATION_CODE, function(err, tokens) {
// Now tokens contains an access_token and an optional refresh_token. Save them.
if (!err) {
oauth2Client.setCredentials(tokens);
uploadVideo();
} else {
console.log(err);
}
});
如果用户获得正确频道的授权码,视频将上传到同一频道