首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何从firebase云函数上传视频到youtube

如何从firebase云函数上传视频到youtube
EN

Stack Overflow用户
提问于 2020-07-09 10:23:38
回答 1查看 504关注 0票数 0

有没有办法将视频从firebase云功能上传到youtube?

如果可能,如果我们使用firebase云函数上传2 Gb数据,2 Gb数据传输收费吗?更改$0.12*2

EN

回答 1

Stack Overflow用户

发布于 2020-07-09 20:27:35

您可以将Nodejs客户端库用于Youtube API。我建议你浏览Quickstart for this client library并访问YouTube API Samples,在那里你可以找到一个如何上传视频的示例:

代码语言:javascript
运行
复制
'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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62806416

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档