A bot that randomly sends a SCANDAL MV at a fixed time every day
I referred to the YouTube Data API reference based on the Qiita article.
Qiita https://qiita.com/sakakinn/items/46c0d4945e4646f346f6
YouTube Data API https://developers.google.com/youtube/v3/docs?hl=ja
index.html.erb
<% number = 0 %>
<% ran = rand(1..11) %>
<% @youtube_data.items.each do |item| %>
<% number = number + 1 %>
<% if number == ran %>
<% snippet = item.snippet %>
<p><%= snippet.title %></p>
<p><%= snippet.published_at %><%= snippet.channel_title %></p>
<div><iframe width="560" height="315" src="https://www.youtube.com/embed/<%= item.id.video_id %>" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>
<% end %>
<% end %>
youtube_controller.rb
class YoutubeController < ApplicationController
def find_videos(keyword)
service = Google::Apis::YoutubeV3::YouTubeService.new
service.key = ENV["YOUTUBEKEY"]
next_page_token = nil
opt = {
q: keyword,
type: 'video',
channel_id: 'UCSNX8VGaawLFG_bAZuMyQ3Q',
max_results: 11,
order: :date,
page_token: next_page_token
}
service.list_searches(:snippet, opt)
end
def index
@youtube_data = find_videos('SCANDAL')
end
end
Output result ↓ https://twitter.com/pompom06yutoz/status/1273869183491559425?s=21
For the time being, try using this as a LINE bot, and think about it when an issue emerges.
It's been about 4 months since I started learning programming, and I'm enjoying it so much. If you have any good alternatives, please feel free to comment. Also, if you like SCANDAL, please do. to be continued
Recommended Posts