Created
April 4, 2019 04:43
-
-
Save ggomagundan/f84aa93b66cc63207fcb730b75f14176 to your computer and use it in GitHub Desktop.
Youtube Subscribers count parsing
This file contains 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
# youtube_checker.rb | |
require 'json' | |
require 'httparty' | |
require 'dotenv' | |
Dotenv.load | |
# Need to install | |
# gem install httpart | |
# gem install dotenv | |
endpoint = ENV["endpoint"] | |
key = ENV["key"] | |
channel = ENV["channel"] | |
. | |
response = HTTParty.get("#{endpoint}?key=#{key}&id=#{channel}&part=statistics") | |
json = JSON.parse(response.body) | |
puts json&.dig("items")[0]&.dig("statistics")&.dig("subscriberCount") | |
# .env | |
endpoint = "https://www.googleapis.com/youtube/v3/channels" | |
key = "KEY_FROM_GOOGLE_CONSOLE" | |
channel = "CHANNEL_ID_FROM_YOUTUBE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment