YouTube · Ruby
require "json"
require "net/http"
uri = URI("https://www.searchapi.io/api/v1/search")
uri.query = URI.encode_www_form(
"engine" => "youtube",
"gl" => "US",
"hl" => "en",
"q" => "pulling an espresso shot"
)
request = Net::HTTP::Get.new(uri, "Authorization" => "Bearer #{ENV.fetch("SEARCHAPI_API_KEY")}")
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) }
puts JSON.parse(response.body)
require "json"
require "net/http"
uri = URI("https://www.searchapi.io/api/v1/search")
uri.query = URI.encode_www_form(
"engine" => "youtube",
"gl" => "US",
"hl" => "en",
"q" => "pulling an espresso shot"
)
request = Net::HTTP::Get.new(uri, "Authorization" => "Bearer #{ENV.fetch("SEARCHAPI_API_KEY")}")
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) }
puts JSON.parse(response.body)
The key is read from SEARCHAPI_API_KEY and sent as a Bearer token.