youtubeで指定のキーワードで検索しその検索結果の上位5つの動画をアプリのviewに表示したいです。
controller.rb
1 2 require 'rubygems' 3 require 'google/api_client' 4 require 'trollop' 5 6 DEVELOPER_KEY = 'APIキー' 7 YOUTUBE_API_SERVICE_NAME = 'youtube' 8 YOUTUBE_API_VERSION = 'v3' 9 10 def get_service 11 client = Google::APIClient.new( 12 :key => DEVELOPER_KEY, 13 :authorization => nil, 14 :application_name => $PROGRAM_NAME, 15 :application_version => '1.0.0', 16 ) 17 youtube = client.discovered_api(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION) 18 19 return client, youtube 20 end 21end 22 23 def index 24 get_data("横浜ベイスターズ応援歌") 25 end 26 27 def get_data(keyword) 28 require 'cheer.rb' 29 opts = Trollop::options do 30 opt :q, 'Search term', :type => String, :default => keyword 31 opt :max_results, 'Max results', :type => :int, :default => 50 32 opt :order, 'order', :type => String, :default => 'date' 33 opt :regionCode, 'region', :type => String, :default => 'JP' 34 end 35 36 client, youtube = get_service 37 38 begin 39 search_response = client.execute!( 40 :api_method => youtube.search.list, 41 :parameters => { 42 :part => 'snippet', 43 :q => opts[:q], 44 :maxResults => opts[:max_results], 45 :order => opts[:order], 46 :regionCode => opts[:regionCode] 47 } 48 ) 49 50 @movies = search_response.data.item 51 binding.pry 52 rescue Google::APIClient::TransmissionError => e 53 puts e.result.body 54 end 55 end
コントローラーでこのような感じで書いてます。
index.htmlにどのように記述すれば良いかご教授いただければと思います。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。