有没有办法将视频从firebase云功能上传到youtube?
如果可能,如果我们使用firebase云函数上传2 Gb数据,2 Gb数据传输收费吗?更改$0.12*2
发布于 2020-07-09 20:27:35
您可以将Nodejs客户端库用于Youtube API。我建议你浏览Quickstart for this client library并访问YouTube API Samples,在那里你可以找到一个如何上传视频的示例:
'use strict';
/**
* Usage: node upload.js PATH_TO_VIDEO_FILE
*/
const fs = require('fs');
const path = require('path');
const readline = require('readline');
const {google} = require('googleapis');
const {authenticate} = require('@google-cloud/local-auth');
// initialize the Youtube API library
const youtube = google.youtube('v3');
// very basic example of uploading a video to youtube
async function runSample(fileName) {
// Obtain user credentials to use for the request
const auth = await authenticate({
keyfilePath: path.join(__dirname, '../oauth2.keys.json'),
scopes: [
'https://www.googleapis.com/auth/youtube.upload',
'https://www.googleapis.com/auth/youtube',
],
});
google.options({auth});
const fileSize = fs.statSync(fileName).size;
const res = await youtube.videos.insert(
{
part: 'id,snippet,status',
notifySubscribers: false,
requestBody: {
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),
},
},
{
// Use the `onUploadProgress` event from Axios to track the
// number of bytes uploaded to this point.
onUploadProgress: evt => {
const progress = (evt.bytesRead / fileSize) * 100;
readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0, null);
process.stdout.write(`${Math.round(progress)}% complete`);
},
}
);
console.log('\n\n');
console.log(res.data);
return res.data;
}
if (module === require.main) {
const fileName = process.argv[2];
runSample(fileName).catch(console.error);
}
module.exports = runSample;
在价格方面,Youtube API是免费的,但您的费用将取决于您选择的Firebase plan。
https://stackoverflow.com/questions/62806416
复制相似问题