-
Notifications
You must be signed in to change notification settings - Fork 278
Expand file tree
/
Copy pathBingVideoSearchv7.rb
More file actions
42 lines (31 loc) · 1.26 KB
/
BingVideoSearchv7.rb
File metadata and controls
42 lines (31 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'net/https'
require 'uri'
require 'json'
# **********************************************
# *** Update or verify the following values. ***
# **********************************************
# Replace the accessKey string value with your valid access key.
accessKey = "enter key here"
# Verify the endpoint URI. At this writing, only one endpoint is used for Bing
# search APIs. In the future, regional endpoints may be available. If you
# encounter unexpected authorization errors, double-check this value against
# the endpoint for your Bing Search instance in your Azure dashboard.
uri = "https://api.cognitive.microsoft.com"
path = "/bing/v7.0/videos/search"
term = "kittens"
uri = URI(uri + path + "?q=" + URI.escape(term))
puts "Searching videos for: " + term
request = Net::HTTP::Get.new(uri)
request['Ocp-Apim-Subscription-Key'] = accessKey
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
http.request(request)
end
puts "\nRelevant Headers:\n\n"
response.each_header do |key, value|
# header names are coerced to lowercase
if key.start_with?("bingapis-") or key.start_with?("x-msedge-") then
puts key + ": " + value
end
end
puts "\nJSON Response:\n\n"
puts JSON::pretty_generate(JSON(response.body))