如何访问Youtube_it ruby查询结果?

如何访问Youtube_it ruby查询结果?,ruby,xml,youtube,Ruby,Xml,Youtube,我正在尝试为ruby实现youtube api包装器,并使其正常工作,但对于如何访问查询结果,我感到困惑 我的问题是: client.videos_by(:query => "penguin", :max_results => 1) Submitting request [url=http://gdata.youtube.com/feeds/api/videos?max-results=1&start-index=1&vq=penguin]. => #<Y

我正在尝试为ruby实现youtube api包装器,并使其正常工作,但对于如何访问查询结果,我感到困惑

我的问题是:

client.videos_by(:query => "penguin", :max_results => 1)
Submitting request [url=http://gdata.youtube.com/feeds/api/videos?max-results=1&start-index=1&vq=penguin].
=> #<YouTubeIt::Response::VideoSearch:0xb6c41b14 @feed_id="http://gdata.youtube.com/feeds/api/videos", @updated_at=Wed Nov 03 18:01:39 UTC 2010, @videos=[#<YouTubeIt::Model::Video:0xb6c424d8 @thumbnails=[#<YouTubeIt::Model::Thumbnail:0xb6c6b694 @url="http://i.ytimg.com/vi/oSbLpQEZP1Y/2.jpg", @width=120, @height=90, @time="00:01:34">, #<YouTubeIt::Model::Thumbnail:0xb6c6b248 @url="http://i.ytimg.com/vi/oSbLpQEZP1Y/1.jpg", @width=120, @height=90, @time="00:00:47">, #<YouTubeIt::Model::Thumbnail:0xb6c6a988 @url="http://i.ytimg.com/vi/oSbLpQEZP1Y/3.jpg", @width=120, @height=90, @time="00:02:21">, #<YouTubeIt::Model::Thumbnail:0xb6c69e34 @url="http://i.ytimg.com/vi/oSbLpQEZP1Y/0.jpg", @width=320, @height=240, @time="00:01:34">], @categories=[#<YouTubeIt::Model::Category:0xb6ca5d6c @term="Music", @label="Music">], @noembed=false, @racy=false, @favorite_count=7862, @duration=188, @author=#<YouTubeIt::Model::Author:0xb6c9942c @name="wili", @uri="http://gdata.youtube.com/feeds/api/users/wili">, @updated_at=Tue Nov 02 08:45:25 UTC 2010, @longitude=nil, @position=nil, @view_count=1682350, @html_content="penguin", @media_content=[#<YouTubeIt::Model::Content:0xb6c770d4 @url="http://www.youtube.com/v/oSbLpQEZP1Y?f=videos&app=youtube_gdata", @duration=188, @format=#<YouTubeIt::Model::Video::Format:0xb656d108 @name=:swf, @format_code=5>, @default=true, @mime_type="application/x-shockwave-flash">, #<YouTubeIt::Model::Content:0xb6c766d4 @url="rtsp://v5.cache3.c.youtube.com/CiILENy73wIaGQlWPxkBpcsmoRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", @duration=188, @format=#<YouTubeIt::Model::Video::Format:0xb656d11c @name=:rtsp, @format_code=1>, @default=false, @mime_type="video/3gpp">, #<YouTubeIt::Model::Content:0xb6c75d38 @url="rtsp://v8.cache3.c.youtube.com/CiILENy73wIaGQlWPxkBpcsmoRMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", @duration=188, @format=#<YouTubeIt::Model::Video::Format:0xb656d0f4 @name=:three_gpp, @format_code=6>, @default=false, @mime_type="video/3gpp">], @description="penguin", @latitude=nil, @title="penguin", @published_at=Mon May 08 18:11:01 UTC 2006, @player_url="http://www.youtube.com/watch?v=oSbLpQEZP1Y&feature=youtube_gdata_player", @rating=#<YouTubeIt::Model::Rating:0xb6c5eb4c @min=1, @max=5, @average=4.676985, @rater_count=2746>, @keywords=["pigloo", "penguin"], @video_id="http://gdata.youtube.com/feeds/api/videos/oSbLpQEZP1Y", @where=nil>], @total_result_count=291282, @offset=1, @max_result_count=1>
client.videos\u by(:query=>“企鹅”,:max\u results=>1)
提交请求[url]=http://gdata.youtube.com/feeds/api/videos?max-结果=1,开始索引=1,vq=penguin]。
=> #

我想检索URL和缩略图链接。有什么想法吗?

我对这个宝石不太了解,但你的答案至少应该接近这个。您可以通过
视频
访问器直接访问对象,该访问器将为您提供视频对象,
缩略图
上都有
url
。因此,您可以执行以下操作:

reply = client.videos_by(:query => "penguin", :max_results => 1)
reply.videos.first.thumbnails.first.url # the thumbnail for the first video
reply.videos.first.player_url # The website for the video
reply.videos.first.media_content.first.url # direct embed url

搜索一些ruby初学者指南可能会很有用,可以帮助您跟上速度。祝你好运

当你这么做的时候,威廉的答案是正确的

client.videos_by(:query => "penguin", :max_results => 1)
这将返回一个名为videos的数组,因此您只需要迭代它

client.videos.each do |video|
  video.title
  video.thumbnails
  video.video_id
end

祝你好运

你太棒了。以您的示例为例,我不知道在reply时调用哪些方法,但reply.videos.first的工作方式非常出色。谢谢