I’m building an app in Ruby that checks if a specific streamer is currently broadcasting. However, when I attempt to make an API request, I receive a 401 error.
require "launchy"
require "colorize"
require 'rest-client'
require "json"
require_relative "lib/config/config.rb"
puts "What's your streamer name: ".green
streamer = gets.chomp
url = "https://api.twitch.tv/helix/streams?user_login=#{streamer}"
response = RestClient.get(url, headers: {
"Authorization": "Bearer " + Config.token,
"Client-Id": Config.client_id
})
config file:
require "dotenv/load"
module Config
def self.client_id
client_ID = ENV["CLIENT_ID"]
end
def self.token
token = ENV["TOKEN"]
end
end
When I tried to make a request with Postman, I received the following JSON response:
{
"error": "Unauthorized",
"status": 401,
"message": "OAuth token is missing"
}
I don’t know if the issue has to do with OAuth when I registered my application with redirect urls as http://localhost because I didn’t think I would need a local server to make a simple request.