Google apps script GAS:大多数文件的Blob上传到YouTube失败

Google apps script GAS:大多数文件的Blob上传到YouTube失败,google-apps-script,youtube-api,Google Apps Script,Youtube Api,我正在尝试使用谷歌应用程序脚本将文件从谷歌硬盘上传到YouTube 我只成功上传了约2MB的视频 这样做的主要原因是互联网上的上传速度慢,有时不可靠,所以让谷歌硬盘处理起来更容易,但要将大于25MB的文件上传到YouTube上却很难 该脚本需要从“资源”>“高级谷歌服务”启用“YouTube数据API…” 功能代码: // Upload Google Drive file to youtube function uploadFileToYouTube(file) { var name = f

我正在尝试使用谷歌应用程序脚本将文件从谷歌硬盘上传到YouTube

我只成功上传了约2MB的视频

这样做的主要原因是互联网上的上传速度慢,有时不可靠,所以让谷歌硬盘处理起来更容易,但要将大于25MB的文件上传到YouTube上却很难

该脚本需要从“资源”>“高级谷歌服务”启用“YouTube数据API…”

功能代码:

// Upload Google Drive file to youtube
function uploadFileToYouTube(file) {
  var name = file.getName();
  var size = file.getSize();
  var type = file.getMimeType();
  var blob = file.getBlob();
  var access = file.getSharingAccess();
  var yt_privacy;
  // Attempt to preserve permissions from Drive
  switch(access) {
    case DriveApp.Access.PRIVATE:
      yt_privacy = "private";
      break;
    case DriveApp.Access.ANYONE:
      yt_privacy = "public";
      break;
    case DriveApp.Access.ANYONE_WITH_LINK:
      yt_privacy = "unlisted";
      break;
    default:
      yt_privacy = "private";
  }
  Logger.log("File: "+name+" Size: "+size+" Type: "+type+" Access: "+access+" YT privacy: "+yt_privacy);
  // Actually upload to YouTube....
  var vid_res = {
    snippet: {
      title: name,
      description: "Uploaded from Google Drive\nOriginal size: "+size+"\nOriginal filename: "+name+"\nOriginal mime type: "+type,
    },
    status: {
      privacyStatus: yt_privacy
    }
  }
  try {
    var yt_upload = YouTube.Videos.insert(vid_res,"snippet,status",blob);
    Logger.log(yt_upload);
  } catch (e) {
    Logger.log('Error uploading: '+ name + " Message: " + e.message);
  }
  return yt_upload;
}

// Test function. Needs test.avi on your Google drive
function testUpload() {
  var file = DriveApp.getFilesByName("test.avi").next();
  uploadFileToYouTube(file);
}
日志:

执行记录:

[13-12-30 13:18:33:518 SAST] Starting execution
[13-12-30 13:18:33:527 SAST] DriveApp.getFilesByName([SUNP0017.avi]) [0 seconds]
[13-12-30 13:18:34:799 SAST] (class).next() [1.271 seconds]
[13-12-30 13:18:34:799 SAST] File.getName() [0 seconds]
[13-12-30 13:18:34:799 SAST] File.getSize() [0 seconds]
[13-12-30 13:18:34:799 SAST] File.getMimeType() [0 seconds]
[13-12-30 13:18:34:799 SAST] File.getBlob() [0 seconds]
[13-12-30 13:18:34:921 SAST] File.getSharingAccess() [0.121 seconds]
[13-12-30 13:18:34:924 SAST] Logger.log([File: SUNP0017.avi Size: 35258368 Type: video/x-msvideo Access: ANYONE_WITH_LINK YT privacy: unlisted, []]) [0 seconds]
[13-12-30 13:18:40:474 SAST] Blob.getBytes() [5.549 seconds]
[13-12-30 13:18:40:504 SAST] Blob.getContentType() [0 seconds]
[13-12-30 13:18:45:924 SAST] Logger.log([Error uploading: SUNP0017.avi Message: We're sorry, a server error occurred. Please wait a bit and try again., []]) [0 seconds]
[13-12-30 13:18:45:924 SAST] Execution succeeded [12.398 seconds total runtime]
较小文件的日志:(工作)

[13-12-30 13:19:59:720 SAST]文件:SUNP0024.avi大小:3964928类型:视频/x-msvideo访问:有链接的任何人的隐私:未列出
[13-12-30 13:20:01:579 SAST]{id=,etag=“”,status={publicStatsViewable=true,privacyStatus=unlisted,embedded=true,uploadStatus=uploadStatus=upload,license=youtube},snippet={publishedAt=2013-12-30T11:20:00.000Z,title=SUNP0024.avi,channelId=,description=从谷歌硬盘上传
原版尺寸:3964928
原始文件名:SUNP0024.avi
原始mime类型:video/x-msvideo,categoryId=22,channelTitle=Gert van den Berg,缩略图={default={url=},high={url=},medium={url=}},liveBroadcastContent=none},kind=youtube#video}
小档案成绩单:(作品)

[13-12-30 13:19:58:311 SAST]开始执行
[13-12-30 13:19:58:320 SAST]DriveApp.getFilesByName([SUNP0024.avi])[0秒]
[13-12-30 13:19:59:549 SAST](类).next()[1.229秒]
[13-12-30 13:19:59:550 SAST]File.getName()[0秒]
[13-12-30 13:19:59:554 SAST]File.getSize()[0.002秒]
[13-12-30 13:19:59:558 SAST]File.getMimeType()[0.002秒]
[13-12-30 13:19:59:559 SAST]File.getBlob()[0秒]
[13-12-30 13:19:59:719 SAST]File.getSharingAccess()[0.157秒]
[13-12-30 13:19:59:721 SAST]Logger.log([文件:SUNP0024.avi大小:3964928类型:video/x-msvideo访问:任何具有链接YT隐私的人:未列出,[])[0秒]
[13-12-30 13:20:00:756 SAST]Blob.getBytes()[1.034秒]
[13-12-30 13:20:00:759 SAST]Blob.getContentType()[0秒]
[13-12-30 13:20:01:579 SAST]Logger.log([{id=,etag=,status={publicstatsvievable=true,privacyStatus=unlisted,embeddeble=true,uploadStatus=upload,license=youtube},snippet={publishedAt=2013-12-30T11:20:00.000Z,title=SUNP0024.avi,channelId=,description=从谷歌硬盘上传
原版尺寸:3964928
原始文件名:SUNP0024.avi
原始mime类型:video/x-msvideo,categoryId=22,channelTitle=Gert van den Berg,缩略图={default={url=},high={url=},medium={url=}},liveBroadcastContent=none},kind=youtube#video},[])[0秒]
[13-12-30 13:20:01:579 SAST]执行成功[3.26秒总运行时间]

现在,这是不可能的。API中有blob限制。因为他们为此创建了一种不同的方法,所以最好的办法是创建一个Python或PHP脚本并执行它,而不是应用程序脚本

从应用程序脚本可能还有另一种方法,避免blob?(准确的YouTube API调用可以更好地记录…(AutoComplete是一个没有Blob参数的insert调用版本,但不清楚如何上传文件…)使用脚本的主要原因是,我可以让Google Drive处理上传,然后快速将其传输到YouTube。。。有了Python/PHP,我可能需要下载并重新上传文件,在这种情况下,我也可以直接从我的PC上传文件。。。(512kbps上传…(我可能可以使用我的亚马逊实例,但我希望有一个快速的解决方案,这就是apps scrip的用途…)你是对的,这将是最简单和最好的解决方案。但不幸的是,它现在在应用程序脚本中不可用。
[13-12-30 13:18:33:518 SAST] Starting execution
[13-12-30 13:18:33:527 SAST] DriveApp.getFilesByName([SUNP0017.avi]) [0 seconds]
[13-12-30 13:18:34:799 SAST] (class).next() [1.271 seconds]
[13-12-30 13:18:34:799 SAST] File.getName() [0 seconds]
[13-12-30 13:18:34:799 SAST] File.getSize() [0 seconds]
[13-12-30 13:18:34:799 SAST] File.getMimeType() [0 seconds]
[13-12-30 13:18:34:799 SAST] File.getBlob() [0 seconds]
[13-12-30 13:18:34:921 SAST] File.getSharingAccess() [0.121 seconds]
[13-12-30 13:18:34:924 SAST] Logger.log([File: SUNP0017.avi Size: 35258368 Type: video/x-msvideo Access: ANYONE_WITH_LINK YT privacy: unlisted, []]) [0 seconds]
[13-12-30 13:18:40:474 SAST] Blob.getBytes() [5.549 seconds]
[13-12-30 13:18:40:504 SAST] Blob.getContentType() [0 seconds]
[13-12-30 13:18:45:924 SAST] Logger.log([Error uploading: SUNP0017.avi Message: We're sorry, a server error occurred. Please wait a bit and try again., []]) [0 seconds]
[13-12-30 13:18:45:924 SAST] Execution succeeded [12.398 seconds total runtime]
[13-12-30 13:19:59:720 SAST] File: SUNP0024.avi Size: 3964928 Type: video/x-msvideo Access: ANYONE_WITH_LINK YT privacy: unlisted
[13-12-30 13:20:01:579 SAST] {id=<removed>, etag="<removed>", status={publicStatsViewable=true, privacyStatus=unlisted, embeddable=true, uploadStatus=uploaded, license=youtube}, snippet={publishedAt=2013-12-30T11:20:00.000Z, title=SUNP0024.avi, channelId=<removed>, description=Uploaded from Google Drive
Original size: 3964928
Original filename: SUNP0024.avi
Original mime type: video/x-msvideo, categoryId=22, channelTitle=Gert van den Berg, thumbnails={default={url=<removed>}, high={url=<removed>}, medium={url=<removed>}}, liveBroadcastContent=none}, kind=youtube#video}
[13-12-30 13:19:58:311 SAST] Starting execution
[13-12-30 13:19:58:320 SAST] DriveApp.getFilesByName([SUNP0024.avi]) [0 seconds]
[13-12-30 13:19:59:549 SAST] (class).next() [1.229 seconds]
[13-12-30 13:19:59:550 SAST] File.getName() [0 seconds]
[13-12-30 13:19:59:554 SAST] File.getSize() [0.002 seconds]
[13-12-30 13:19:59:558 SAST] File.getMimeType() [0.002 seconds]
[13-12-30 13:19:59:559 SAST] File.getBlob() [0 seconds]
[13-12-30 13:19:59:719 SAST] File.getSharingAccess() [0.157 seconds]
[13-12-30 13:19:59:721 SAST] Logger.log([File: SUNP0024.avi Size: 3964928 Type: video/x-msvideo Access: ANYONE_WITH_LINK YT privacy: unlisted, []]) [0 seconds]
[13-12-30 13:20:00:756 SAST] Blob.getBytes() [1.034 seconds]
[13-12-30 13:20:00:759 SAST] Blob.getContentType() [0 seconds]
[13-12-30 13:20:01:579 SAST] Logger.log([{id=<removed>, etag="<removed>", status={publicStatsViewable=true, privacyStatus=unlisted, embeddable=true, uploadStatus=uploaded, license=youtube}, snippet={publishedAt=2013-12-30T11:20:00.000Z, title=SUNP0024.avi, channelId=<removed>, description=Uploaded from Google Drive
Original size: 3964928
Original filename: SUNP0024.avi
Original mime type: video/x-msvideo, categoryId=22, channelTitle=Gert van den Berg, thumbnails={default={url=<removed>}, high={url=<removed>}, medium={url=<removed>}}, liveBroadcastContent=none}, kind=youtube#video}, []]) [0 seconds]
[13-12-30 13:20:01:579 SAST] Execution succeeded [3.26 seconds total runtime]