Created
June 27, 2012 11:10
-
-
Save bisque33/3003400 to your computer and use it in GitHub Desktop.
Rubygem youtuber sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'youtuber' | |
# developer_key などをセットしてGDataオブジェクトを作成 | |
gdata = YouTubeR::GData.new("<email@google.com>", "<password>", "<developer_key>", "<app_name>") | |
# search_feeds メソッドでは YoutubeAPI の検索パラメータが使える | |
# https://developers.google.com/youtube/2.0/reference?hl=ja#Searching_for_videos | |
# ここで返ってくるのは YoutubeAPIの生のレスポンス | |
xml_videos_feed = gdata.search_feeds(:q => "git", :orderby => "viewCount", :"max-results" => 10) | |
# GDataとレスポンスを渡して Videos オブジェクトを作る | |
# これによりXMLを簡単にパースして必要な要素だけ取り出せるようになる | |
videos = YouTubeR::Videos.new( xml_videos_feed, gdata ) | |
# Videos を一つ一つ取り出して ID を取得する | |
# あとはそれを Youtubeプレイヤーツール に埋め込んであげればOK | |
# https://developers.google.com/youtube/player_parameters?hl=ja | |
videos.each do |video| | |
p video.id | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment