You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Google Apps Script将Google Drive内的视频上传到YouTube

Google Apps Script 实现Google Drive视频上传到YouTube的方案

前置配置

  • 打开Google Apps Script项目编辑器,点击左侧「服务」选项,添加「YouTube Data API v3」服务
  • 脚本首次运行时会触发授权流程,按提示授予Google Drive读取权限、YouTube账号编辑权限即可

适配后的可运行代码

把原有从URL拉取资源的逻辑替换为从Google Drive读取文件Blob即可,代码如下:

function uploadFromDrive(driveFileId, title, description, topics) {
    try {
        // 从Google Drive获取对应视频文件
        const videoFile = DriveApp.getFileById(driveFileId);
        const videoBlob = videoFile.getBlob();

        // 调用YouTube接口上传
        YouTube.Videos.insert({
            snippet: {
                title: title,
                description: description,
                tags: topics
            },
            status: {
                privacyStatus: "public", // 可根据需求改为private、unlisted
            },
        }, "snippet,status", videoBlob);

        return ContentService.createTextOutput("上传成功")
    } catch (err) {
        return ContentService.createTextOutput("错误:" + err.message)
    }
}

注意事项

  • Google Drive文件ID获取方式:打开对应视频文件,浏览器地址栏中https://drive.google.com/file/d/之后、/view之前的字符串即为文件ID
  • 上传规则和YouTube网页端上传一致,视频大小不能超过128GB,格式需为YouTube支持的视频格式
  • 以上基础代码适合小体积视频上传,大体积视频建议额外添加分片上传、断点续传逻辑避免上传中断失败
  • 如遇权限报错,检查你当前登录的Google账号是否同时有Drive文件的访问权限和YouTube频道的上传权限

内容的提问来源于stack exchange,提问作者idk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 11:30:02