尝试进行简单搜索时使用 YouTube_IT 时出现问题 - Rails 3.1

发布于 2024-12-04 19:32:17 字数 4381 浏览 1 评论 0原文

我正在使用这个 gem: https://github.com/kylejginavan/youtube_it

我的 VideosController< /code> 看起来像这样:

class VideosController < ApplicationController
  def index
  client = YouTubeIt::Client.new(:username => YouTubeITConfig.username , :password => YouTubeITConfig.password , :dev_key => YouTubeITConfig.dev_key)
@video = client.videos_by(:user => 'marcamillion1983')

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @video }
    end
  end

我的观点:

<%= @video %>

输出是这样的:

#<YouTubeIt::Response::VideoSearch:0x0000012995f7c0>

当我尝试执行 @video.each do |video| 时,它给我一个未知方法 each 的错误>。

但是,当我在 Ruby 提示符下尝试该查询时,它会返回结果:

ruby-1.9.2-p0 > client.videos_by(:user => 'marcamillion1983')
 => #<YouTubeIt::Response::VideoSearch:0x000001290484c0 @feed_id="tag:youtube.com,2008:user:marcamillion1983:uploads", @updated_at=2011-09-14 10:32:31 UTC, @total_result_count=1, @offset=1, @max_result_count=25, @videos=[#<YouTubeIt::Model::Video:0x00000129049050 @video_id="tag:youtube.com,2008:video:VY-Ch8OpjvY", @published_at=2011-03-04 18:49:56 UTC, @updated_at=2011-04-02 20:13:14 UTC, @categories=[#<YouTubeIt::Model::Category:0x00000100b430b0 @term="Comedy", @label="Comedy">], @keywords=["laughing baby", "funny baby", "funny laugh", "hysterical laugh", "laughing hysterically", "baby", "funny video", "home video", "cute baby", "cute baby laugh", "5 month old"], @title="Baby Laughing Hysterically at Mummy", @html_content=nil, @author=#<YouTubeIt::Model::Author:0x00000100a308f8 @name="marcamillion1983", @uri="http://gdata.youtube.com/feeds/api/users/marcamillion1983">, @description="Mia-Kalani (5 months at the time) was about to eat and Mummy was playing with her when she started laughing, so she decided to record it.\n\nEnjoy :)", @duration=38, @media_content=[#<YouTubeIt::Model::Content:0x000001008424d8 @url="http://www.youtube.com/v/VY-Ch8OpjvY?f=user_uploads&d=ATs-A8zzS5exgl44oxOFQt4O88HsQjpE1a8d1GxQnGDm&app=youtube_gdata", @format=#<YouTubeIt::Model::Video::Format:0x00000101428220 @format_code=5, @name=:swf>, @duration=38, @mime_type="application/x-shockwave-flash", @default=true>, #<YouTubeIt::Model::Content:0x00000100840c28 @url="rtsp://v8.cache6.c.youtube.com/CksLENy73wIaQgn2jqnDh4KPVRMYDSANFEgGUgx1c2VyX3VwbG9hZHNyIQE7PgPM80uXsYJeOKMThULeDvPB7EI6RNWvHdRsUJxg5gw=/0/0/0/video.3gp", @format=#<YouTubeIt::Model::Video::Format:0x00000101428248 @format_code=1, @name=:rtsp>, @duration=38, @mime_type="video/3gpp", @default=false>, #<YouTubeIt::Model::Content:0x0000010083efe0 @url="rtsp://v5.cache4.c.youtube.com/CksLENy73wIaQgn2jqnDh4KPVRMYESARFEgGUgx1c2VyX3VwbG9hZHNyIQE7PgPM80uXsYJeOKMThULeDvPB7EI6RNWvHdRsUJxg5gw=/0/0/0/video.3gp", @format=#<YouTubeIt::Model::Video::Format:0x000001014281f8 @format_code=6, @name=:three_gpp>, @duration=38, @mime_type="video/3gpp", @default=false>], @player_url="http://www.youtube.com/watch?v=VY-Ch8OpjvY&feature=youtube_gdata_player", @thumbnails=[#<YouTubeIt::Model::Thumbnail:0x000001277e15d0 @url="http://i.ytimg.com/vi/VY-Ch8OpjvY/default.jpg", @height=90, @width=120, @time="00:00:19">, #<YouTubeIt::Model::Thumbnail:0x000001277e0fe0 @url="http://i.ytimg.com/vi/VY-Ch8OpjvY/hqdefault.jpg", @height=360, @width=480, @time=nil>, #<YouTubeIt::Model::Thumbnail:0x000001277e09f0 @url="http://i.ytimg.com/vi/VY-Ch8OpjvY/1.jpg", @height=90, @width=120, @time="00:00:09.500">, #<YouTubeIt::Model::Thumbnail:0x000001277e0400 @url="http://i.ytimg.com/vi/VY-Ch8OpjvY/2.jpg", @height=90, @width=120, @time="00:00:19">, #<YouTubeIt::Model::Thumbnail:0x000001277dfe10 @url="http://i.ytimg.com/vi/VY-Ch8OpjvY/3.jpg", @height=90, @width=120, @time="00:00:28.500">], @rating=#<YouTubeIt::Model::Rating:0x00000129001520 @min=1, @max=5, @rater_count=2, @average=5.0, @likes=2, @dislikes=0>, @view_count=276, @favorite_count=1, @widescreen=nil, @noembed=false, @racy=false, @where=nil, @position=nil, @latitude=nil, @longitude=nil, @state={:name=>"published"}>]> 

如何获得正确的输出,以便可以在视图上显示视频?

谢谢。

I am using this gem: https://github.com/kylejginavan/youtube_it

My VideosController looks like this:

class VideosController < ApplicationController
  def index
  client = YouTubeIt::Client.new(:username => YouTubeITConfig.username , :password => YouTubeITConfig.password , :dev_key => YouTubeITConfig.dev_key)
@video = client.videos_by(:user => 'marcamillion1983')

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @video }
    end
  end

My view:

<%= @video %>

The output is this:

#<YouTubeIt::Response::VideoSearch:0x0000012995f7c0>

When I try to do @video.each do |video| it gives me an error for unknown method each.

However, when I try that query at the Ruby prompt, it returns results:

ruby-1.9.2-p0 > client.videos_by(:user => 'marcamillion1983')
 => #<YouTubeIt::Response::VideoSearch:0x000001290484c0 @feed_id="tag:youtube.com,2008:user:marcamillion1983:uploads", @updated_at=2011-09-14 10:32:31 UTC, @total_result_count=1, @offset=1, @max_result_count=25, @videos=[#<YouTubeIt::Model::Video:0x00000129049050 @video_id="tag:youtube.com,2008:video:VY-Ch8OpjvY", @published_at=2011-03-04 18:49:56 UTC, @updated_at=2011-04-02 20:13:14 UTC, @categories=[#<YouTubeIt::Model::Category:0x00000100b430b0 @term="Comedy", @label="Comedy">], @keywords=["laughing baby", "funny baby", "funny laugh", "hysterical laugh", "laughing hysterically", "baby", "funny video", "home video", "cute baby", "cute baby laugh", "5 month old"], @title="Baby Laughing Hysterically at Mummy", @html_content=nil, @author=#<YouTubeIt::Model::Author:0x00000100a308f8 @name="marcamillion1983", @uri="http://gdata.youtube.com/feeds/api/users/marcamillion1983">, @description="Mia-Kalani (5 months at the time) was about to eat and Mummy was playing with her when she started laughing, so she decided to record it.\n\nEnjoy :)", @duration=38, @media_content=[#<YouTubeIt::Model::Content:0x000001008424d8 @url="http://www.youtube.com/v/VY-Ch8OpjvY?f=user_uploads&d=ATs-A8zzS5exgl44oxOFQt4O88HsQjpE1a8d1GxQnGDm&app=youtube_gdata", @format=#<YouTubeIt::Model::Video::Format:0x00000101428220 @format_code=5, @name=:swf>, @duration=38, @mime_type="application/x-shockwave-flash", @default=true>, #<YouTubeIt::Model::Content:0x00000100840c28 @url="rtsp://v8.cache6.c.youtube.com/CksLENy73wIaQgn2jqnDh4KPVRMYDSANFEgGUgx1c2VyX3VwbG9hZHNyIQE7PgPM80uXsYJeOKMThULeDvPB7EI6RNWvHdRsUJxg5gw=/0/0/0/video.3gp", @format=#<YouTubeIt::Model::Video::Format:0x00000101428248 @format_code=1, @name=:rtsp>, @duration=38, @mime_type="video/3gpp", @default=false>, #<YouTubeIt::Model::Content:0x0000010083efe0 @url="rtsp://v5.cache4.c.youtube.com/CksLENy73wIaQgn2jqnDh4KPVRMYESARFEgGUgx1c2VyX3VwbG9hZHNyIQE7PgPM80uXsYJeOKMThULeDvPB7EI6RNWvHdRsUJxg5gw=/0/0/0/video.3gp", @format=#<YouTubeIt::Model::Video::Format:0x000001014281f8 @format_code=6, @name=:three_gpp>, @duration=38, @mime_type="video/3gpp", @default=false>], @player_url="http://www.youtube.com/watch?v=VY-Ch8OpjvY&feature=youtube_gdata_player", @thumbnails=[#<YouTubeIt::Model::Thumbnail:0x000001277e15d0 @url="http://i.ytimg.com/vi/VY-Ch8OpjvY/default.jpg", @height=90, @width=120, @time="00:00:19">, #<YouTubeIt::Model::Thumbnail:0x000001277e0fe0 @url="http://i.ytimg.com/vi/VY-Ch8OpjvY/hqdefault.jpg", @height=360, @width=480, @time=nil>, #<YouTubeIt::Model::Thumbnail:0x000001277e09f0 @url="http://i.ytimg.com/vi/VY-Ch8OpjvY/1.jpg", @height=90, @width=120, @time="00:00:09.500">, #<YouTubeIt::Model::Thumbnail:0x000001277e0400 @url="http://i.ytimg.com/vi/VY-Ch8OpjvY/2.jpg", @height=90, @width=120, @time="00:00:19">, #<YouTubeIt::Model::Thumbnail:0x000001277dfe10 @url="http://i.ytimg.com/vi/VY-Ch8OpjvY/3.jpg", @height=90, @width=120, @time="00:00:28.500">], @rating=#<YouTubeIt::Model::Rating:0x00000129001520 @min=1, @max=5, @rater_count=2, @average=5.0, @likes=2, @dislikes=0>, @view_count=276, @favorite_count=1, @widescreen=nil, @noembed=false, @racy=false, @where=nil, @position=nil, @latitude=nil, @longitude=nil, @state={:name=>"published"}>]> 

How do I get the proper output, so that I can display the video on my view?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

删除→记忆 2024-12-11 19:32:17

虽然我自己没有使用过那个特定的 gem,但看起来视频本身存储在返回的 YouTubeIt::Response::VideoSearch 对象的 videos 属性中。尝试使用 @video.videos.each do |video| 看看是否有效。

Though I haven't used that particular gem myself, it looks the videos themselves are stored in a videos attribute on the YouTubeIt::Response::VideoSearch object that is returned. Try using @video.videos.each do |video| and see if that works.

佞臣 2024-12-11 19:32:17

嘿,我的朋友,我用可用于将 gem youtube_it 与 Rails 集成的资源做了一个示例。您可以在线测试此功能或获取代码,请

参阅此处 http://youtube-it.heroku.com/< /a>

享受吧!

hey my friend I made an example with the sources available for integrate the gem youtube_it with rails. you can test this online or get the code for see

see here http://youtube-it.heroku.com/

enjoy!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文