Twitch Lists of Streamers by Game

From WikiOD

Getting the First Page in Ruby[edit | edit source]

This Ruby example uses Mechanize, a library to automate web interactions.

client_id is an OAuth client_id.

game is the game directory to list.

require 'mechanize'
master_agent = Mechanize.new

client_id = "123"
game = "Minecraft"

url = "https://api.twitch.tv/kraken/streams?game=#{game}&client_id=#{client_id}"
final_list = []
master_agent.get(url) do |page|
    master_list = JSON.parse(page.body)
    master_list["streams"].each do |stream|
        final_list << stream["channel"]["name"]
    end
end

This article is an extract of the original Stack Overflow Documentation created by contributors and released under CC BY-SA 3.0. This website is not affiliated with Stack Overflow