Javascript 如何使用谷歌应用程序脚本将视频上传到YouTube?
我想使用谷歌应用程序脚本将视频上传到YouTube。这是我的代码,包括我尝试过的内容和错误 代码.gsJavascript 如何使用谷歌应用程序脚本将视频上传到YouTube?,javascript,api,google-apps-script,video,youtube,Javascript,Api,Google Apps Script,Video,Youtube,我想使用谷歌应用程序脚本将视频上传到YouTube。这是我的代码,包括我尝试过的内容和错误 代码.gs /** *@见https://developers.google.com/youtube/v3/docs/videos/insert *@param{String}sourceUrl源视频文件在google drive中的位置 *@returns{Video} */ const uploadVideo2youtube=sourceId=>{ const sourceFile=DriveApp.
/**
*@见https://developers.google.com/youtube/v3/docs/videos/insert
*@param{String}sourceUrl源视频文件在google drive中的位置
*@returns{Video}
*/
const uploadVideo2youtube=sourceId=>{
const sourceFile=DriveApp.getFileById(sourceId,).getBlob();
常量视频资源={
片段:{
标题:“加州暑假”,
描述:“在圣克鲁斯冲浪玩得很开心”,
标签:[‘冲浪’、‘圣克鲁斯’、],
类别:“22”,
},
};
//const status={privacyStatus:'Private',};
const status={privacyStatus:'private',};
//以下是我所有的尝试和每一次的错误。。。
//const newVideo=YouTube.Videos.insert(videoResource,status,sourceFile,);//GoogleJsonResponseException:API调用YouTube.Videos.insert失败,错误为:“{privacyStatus=private}”(第229行,文件“Code”)
//const newVideo=YouTube.Videos.insert(videoResource,sourceFile,;//GoogleJsonResponseException:API调用YouTube.Videos.insert失败,错误为:Blob(第230行,文件“代码”)
const newVideo=YouTube.Videos.insert(videoResource,[status],sourceFile,);//GoogleJsonResponseException:API调用YouTube.Videos.insert失败,错误为:“{privacyStatus=private}”(第231行,文件“Code”)
Logger.log('(第213行)newVideo:\n%s',JSON.stringify(newVideo),);
}
const upload2youtube_test=()=>upload2youtube(,)
正如您从代码中看到的,我已经多次尝试使用YouTube.Videos.insert()
方法。但每次尝试都会出错。是的,我已经在我的资源选项卡下启用了YouTube数据API v3资源,并授权脚本运行
我做错了什么?这次修改怎么样 修改点:
- 请在
中包含视频资源
状态
的第二个参数是YouTube.Videos.insert(resource,part,mediaData)
。在本例中,它是part
“snippet,status”
- 在这种情况下,需要在Advanced Google services上启用YouTube数据API v3。请小心这个李>
- 请在
中包含视频资源
状态
的第二个参数是YouTube.Videos.insert(resource,part,mediaData)
。在本例中,它是part
“snippet,status”
- 在这种情况下,需要在Advanced Google services上启用YouTube数据API v3。请小心这个李>
- 这次修改怎么样
修改点:
/**
* @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>, )
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',
},
status: {privacyStatus: 'private'} // Added
};
const newVideo = YouTube.Videos.insert( videoResource, "snippet,status", sourceFile); // Modified