Created
January 1, 2017 06:49
-
-
Save belltailjp/933bfec95c94a224661bd04c31012c29 to your computer and use it in GitHub Desktop.
YouTube Data API v3 + google-api-ruby-client 0.9.20 example for searching movie Raw
This file contains hidden or 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 'google/apis/youtube_v3' | |
require 'active_support/all' | |
GOOGLE_API_KEY="YOUR_API_KEY" | |
def find_videos(keyword, after: 1.months.ago, before: Time.now) | |
service = Google::Apis::YoutubeV3::YouTubeService.new | |
service.key = GOOGLE_API_KEY | |
next_page_token = nil | |
begin | |
opt = { | |
q: keyword, | |
type: 'video', | |
max_results: 50, | |
order: :date, | |
page_token: next_page_token, | |
published_after: after.iso8601, | |
published_before: before.iso8601 | |
} | |
results = service.list_searches(:snippet, opt) | |
results.items.each do |item| | |
snippet = item.snippet | |
puts "\"#{snippet.title}\" by #{snippet.channel_title} (#{snippet.published_at})" | |
end | |
next_page_token = results.next_page_token | |
end while next_page_token.present? | |
end | |
find_videos('レノファ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment