Skip to content

Instantly share code, notes, and snippets.

@bisque33
Created June 27, 2012 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bisque33/3003400 to your computer and use it in GitHub Desktop.
Save bisque33/3003400 to your computer and use it in GitHub Desktop.
Rubygem youtuber sample
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