我在rails 4.2.0和ruby 2.3.0上遇到了yt gem的问题
基本上我使用观察者使用yt gem存储来自youtube链接的数据。但是当gem尝试从youtube获取数据时,我收到HTTP 500错误,并且:
A request to YouTube API returned no items but some were expected: {} You can retry the same request manually by running: curl -X GET -H "content-length: 0" -H "user-agent: Yt::Request (gzip)" -H "host: www.googleapis.com" "https://www.googleapis.com/youtube/v3/videos?id=&key=AIzaSyCdfdv_akpDhDZEOfrrSkws4P2WMXEKDAU&part=snippet"
以下是控制台跟踪:
Started POST "/videos" for ::1 at 2017-05-04 17:05:52 +0200
Processing by VideosController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"+rymp2zyt3eTcZQpGzenHOEnrZelzBpKGXegoLwXDDyIi6oBlyw1iSBhBzH1u5JhGBuAvWx05an61CJg8eaawQ==", "video"=>{"link"=>"https://www.youtube.com/watch?v=UkyV_Ip5vzA"}, "commit"=>"Create Video"}
(0.0ms) begin transaction
(0.5ms) rollback transaction
Completed 500 Internal Server Error in 157ms
Yt::Errors::NoItems (A request to YouTube API returned no items but some were expected:
{}
You can retry the same request manually by running:
curl -X GET -H "content-length: 0" -H "user-agent: Yt::Request (gzip)" -H "host: www.googleapis.com" "https://www.googleapis.com/youtube/v3/videos?id=&key=AIzaSyCdfdv_akpDhDZEOfrrSkws4P2WMXEKDAU&part=snippet"
):
app/models/video_observer.rb:5:in `before_save'
app/controllers/videos_controller.rb:12:in `create'
Rendered C:/Ruby23/lib/ruby/gems/2.3.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_source.erb (1.0ms)
Rendered C:/Ruby23/lib/ruby/gems/2.3.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.0ms)
Rendered C:/Ruby23/lib/ruby/gems/2.3.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.0ms)
Rendered C:/Ruby23/lib/ruby/gems/2.3.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (549.9ms)
Rendered C:/Ruby23/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (0.0ms)
Rendered C:/Ruby23/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.5ms)
Rendered C:/Ruby23/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.0ms)
Rendered C:/Ruby23/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.0ms)
Rendered C:/Ruby23/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb within layouts/javascript (503.4ms)
Rendered C:/Ruby23/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb within layouts/javascript (0.0ms)
Rendered C:/Ruby23/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb within layouts/javascript (1.0ms)
Rendered C:/Ruby23/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (1163.2ms)
我几乎尝试了我在互联网上发现的一切,没有任何效果。有些帖子说ruby和SSL存在问题,但我对此一无所知。
你对可能导致这种情况的原因有什么看法吗?
答案 0 :(得分:-1)
之前我遇到了同样的错误。
当YouTube正在处理视频时,我尝试调用某种方法并得到:
Yt::Errors::NoItems (A request to YouTube API returned no items but some were expected: {}
如果您需要验证成功上传,请尝试使用:
if video.failed? ~> if video.id.present?