【发布时间】:2020-11-21 01:55:48
【问题描述】:
我想使用 Google Apps 脚本将视频上传到 YouTube。这是我的代码,包括我尝试过的内容以及错误所在。
代码.gs/**
* @see https://developers.google.com/youtube/v3/docs/videos/insert
* @param { String } sourceUrl url location of the source video file in google drive
* @returns { Video }
*/
const uploadVideo2youtube = sourceId => {
const sourceFile = DriveApp.getFileById( sourceId, ).getBlob();
const videoResource = {
snippet: {
title: 'Summer vacation in California',
description: 'Had a great time surfing in Santa Cruz',
tags: [ 'surfing', 'Santa Cruz', ],
categoryId: '22',
},
};
// const status = { privacyStatus: 'Private', };
const status = { privacyStatus: 'private', };
// here are all my attempts and the errors with each one...
// const newVideo = YouTube.Videos.insert( videoResource, status, sourceFile, ); // GoogleJsonResponseException: API call to youtube.videos.insert failed with error: '{privacyStatus=private}' (line 229, file "Code")
// const newVideo = YouTube.Videos.insert( videoResource, sourceFile, ); // GoogleJsonResponseException: API call to youtube.videos.insert failed with error: Blob (line 230, file "Code")
const newVideo = YouTube.Videos.insert( videoResource, [ status ], sourceFile, ); // GoogleJsonResponseException: API call to youtube.videos.insert failed with error: '{privacyStatus=private}' (line 231, file "Code")
Logger.log('(line 213) newVideo:\n%s', JSON.stringify( newVideo ),);
}
const upload2youtube_test = () => upload2youtube( <fileId>, )
从代码中可以看出,我对YouTube.Videos.insert()方法做了几次尝试。但是每次尝试都会引发错误。是的,我已在我的资源选项卡下启用了 YouTube 数据 API v3 资源并授权脚本运行。
我做错了什么?
【问题讨论】:
标签: javascript api google-apps-script video youtube