Skip to content

Instantly share code, notes, and snippets.

@ggomagundan
Created April 4, 2019 04:43
Show Gist options
  • Save ggomagundan/f84aa93b66cc63207fcb730b75f14176 to your computer and use it in GitHub Desktop.
Save ggomagundan/f84aa93b66cc63207fcb730b75f14176 to your computer and use it in GitHub Desktop.
Youtube Subscribers count parsing
# 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