加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何访问Youtube_it ruby??查询结果?

发布时间:2020-12-17 02:27:37 所属栏目:百科 来源:网络整理
导读:我正在尝试为 ruby实现 youtube_it youtube api包装并让它工作,除了我对如何访问查询结果感到困惑. 这是我的查询: client.videos_by(:query = "penguin",:max_results = 1)Submitting request [url=http://gdata.youtube.com/feeds/api/videos?max-results=
我正在尝试为 ruby实现 youtube_it 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",@time="00:00:47">,#<YouTubeIt::Model::Thumbnail:0xb6c6a988 @url="http://i.ytimg.com/vi/oSbLpQEZP1Y/3.jpg",@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",@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",@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",@format=#<YouTubeIt::Model::Video::Format:0xb656d0f4 @name=:three_gpp,@format_code=6>,@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>

我想检索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初学者指南可能有助于提高您的速度.祝好运!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读