开发者

Problems using YouTube_IT when trying to do a simple search - Rails 3.1

开发者 https://www.devze.com 2023-04-05 08:02 出处:网络
I am using this gem: https://github.com/kylejginavan/youtube_it My VideosController looks like this: class VideosController < ApplicationController

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.


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.


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号