現在、herokuにデプロイをしています。
いったんindexページが表示され、うまくいったかのように見えたのですがyoutubeのapiをたたいているコードがある部分でエラーが起こっています。色々調べてみると、herokuからは固定ipが必要なものは叩けない!(http://qiita.com/takayukii/items/29e53add44a956b4d539)みたいな記事を見つけてうーん、と唸っています。
検索して回ってみたのですが、ほかにいい情報もあまり見つかりませんでした。こうやって解決した、などご存知の方がいれば教えて欲しいです。ちなみにyoutubeのapiの叩くコードは以下です。developer_keyは略しています。
ruby
1 private 2 def get_service 3 client = Google::APIClient.new( 4 :key => DEVELOPER_KEY, 5 :authorization => nil, 6 :application_name => $PROGRAM_NAME, 7 :application_version => '1.0.0' 8 ) 9 youtube = client.discovered_api(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION) 10 11 return client, youtube 12 end 13 14 def search(keyword) 15 opts = Trollop::options do 16 opt :q, 'Search term', :type => String,:default => "#{keyword} PV 音楽 -歌ってみた -歌った" 17 opt :max_results, 'Max results',:type => :int, :default => 10 18 end 19 20 client, youtube = get_service 21 22 begin 23 # Call the search.list method to retrieve results matching the specified 24 # query term. 25 search_response = client.execute!( 26 :api_method => youtube.search.list, 27 :parameters => { 28 :part => 'snippet', 29 :q => opts[:q], 30 :maxResults => opts[:max_results], 31 :order => 'relevance', 32 :regionCode => 'JP' 33 } 34 ) 35 36 videos = [] 37 channels = [] 38 playlists = [] 39 40 # Add each result to the appropriate list, and then display the lists of 41 # matching videos, channels, and playlists. 42 search_response.data.items.each do |search_result| 43 case search_result.id.kind 44 when 'youtube#video' 45 videos << "#{search_result.id.videoId}" 46 when 'youtube#channel' 47 channels << "#{search_result.snippet.title} (#{search_result.id.channelId})" 48 when 'youtube#playlist' 49 playlists << "#{search_result.snippet.title} (#{search_result.id.playlistId})" 50 end 51 end 52 53 54 rescue Google::APIClient::TransmissionError => e 55 puts e.result.body 56 end 57 58 return videos 59 60 end
追記
具体的にどんなエラーが出るかというと、下のようなサーバーエラーです。
2016-11-01T12:42:20.743344+00:00 app[web.1]: Artist Load (2.1ms) SELECT "artists".* FROM "artists" WHERE "artists"."id" = $1 LIMIT 1 [["id", 710]] 2016-11-01T12:42:20.744569+00:00 app[web.1]: Error: unknown argument '-p'. 2016-11-01T12:42:20.744573+00:00 app[web.1]: Try --help for help. 2016-11-01T12:42:20.744951+00:00 app[web.1]: Completed 500 Internal Server Error in 4ms (ActiveRecord: 2.1ms) 2016-11-01T12:42:20.746350+00:00 app[web.1]: 2016-11-01T12:42:20.746352+00:00 app[web.1]: SystemExit (exit): 2016-11-01T12:42:20.746353+00:00 app[web.1]: app/controllers/artist_controller.rb:152:in `search' 2016-11-01T12:42:20.746354+00:00 app[web.1]: app/controllers/artist_controller.rb:106:in `show_in_detail' 2016-11-01T12:42:20.746355+00:00 app[web.1]: 2016-11-01T12:42:20.746355+00:00 app[web.1]:
searchメソッドはprivateで上に書いてあるメソッドになります。
他にもう1ページ動画が見られるページもあるのですが、そちらも同様に動きません。
なお、ローカル環境では正常に動作をしています。
回答1件
あなたの回答
tips
プレビュー