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

使用YouTube Data API v3设置缩略图遇failedPrecondition错误求助

YouTube Data API v3设置缩略图触发failedPrecondition错误问题

我用YouTube Data API v3搭配Ruby版Google APIs客户端库做视频自动上传、更新和删除已经一年多了。之前上传视频后立刻设置缩略图时,偶尔会碰到配额超限的错误,但我一直远低于服务配额上限,重传缩略图就能解决,大部分时候都正常。

但最近每次上传视频后提交缩略图,都会触发新错误:failedPrecondition: Precondition check failed,而且重传完全没用。我这段时间没改代码,上传视频、更新描述等其他操作都正常,排除了认证或请求格式的问题;缩略图图片大小也小于100K。Google开发者文档里根本没提这个异常,完全找不到问题原因。

我的代码逻辑很简单:

service.set_thumbnail(vid, upload_source: file)

其中vid是视频的YouTube ID,file是图片文件路径,这段代码几天前还能正常运行。

返回的异常栈信息如下:

failedPrecondition: Precondition check failed.

/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/google-apis-core-0.11.1/lib/google/apis/core/http_command.rb:239:in `check_status'
/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/google-apis-core-0.11.1/lib/google/apis/core/api_command.rb:135:in `check_status'
/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/google-apis-core-0.11.1/lib/google/apis/core/http_command.rb:202:in `process_response'
/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/google-apis-core-0.11.1/lib/google/apis/core/upload.rb:174:in `process_response'
/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/google-apis-core-0.11.1/lib/google/apis/core/upload.rb:259:in `execute_once'
/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/google-apis-core-0.11.1/lib/google/apis/core/http_command.rb:126:in `block (2 levels) in do_retry'
/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/retriable-3.1.2/lib/retriable.rb:61:in `block in retriable'
/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/retriable-3.1.2/lib/retriable.rb:56:in `times'
/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/retriable-3.1.2/lib/retriable.rb:56:in `retriable'
/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/google-apis-core-0.11.1/lib/google/apis/core/http_command.rb:123:in `block in do_retry'
/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/retriable-3.1.2/lib/retriable.rb:61:in `block in retriable'
/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/retriable-3.1.2/lib/retriable.rb:56:in `times'
/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/retriable-3.1.2/lib/retriable.rb:56:in `retriable'
/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/google-apis-core-0.11.1/lib/google/apis/core/http_command.rb:113:in `do_retry'
/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/google-apis-core-0.11.1/lib/google/apis/core/http_command.rb:104:in `execute'
/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/google-apis-core-0.11.1/lib/google/apis/core/base_service.rb:418:in `execute_or_queue_command'
/home/uploader/local/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/google-apis-youtube_v3-0.6.0/lib/google/apis/youtube_v3/service.rb:3262:in `set_thumbnail'
/home/uploader/rails/app/controllers/concerns/youtube_handler.rb:63:in `block in set_thumbnail'
/home/uploader/rails/app/controllers/concerns/youtube_handler.rb:62:in `open'
/home/uploader/rails/app/controllers/concerns/youtube_handler.rb:62:in `set_thumbnail'

从栈信息能看到库代码尝试三次上传后失败。

另外补充:我用同一套代码给两个YouTube频道上传视频,之前缩略图上传都正常,现在只有其中一个频道出现这个问题。两个频道在YouTube Studio里看不到任何限制或处罚,怀疑这个错误和频道状态有关。

有没有人遇到过这个错误?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 11:13:12