I am trying to create a new broadcast using google-api-ruby-client
YT = Google::Apis::YoutubeV3
client = YT::YouTubeService.new
client.key = 'my-api-key-here'
metadata = {
snippet: {
title: 'test',
scheduled_start_time: '2018-02-23T14:50:00.000Z'
},
status: {
privacy_status: 'public'
}
}
part = 'snippet'
client.insert_live_broadcast(part, metadata, {})
When I execute this code I am getting Error -# <Google::Apis::AuthorizationError: Unauthorized>
[5] pry(main)> CreateYoutubeBroadcast.execute
Sending HTTP post https://www.googleapis.com/youtube/v3/liveBroadcasts?key=my-api-key&part=snippet
401
#<HTTP::Message:0x007f8d5356fdc8 @http_header=#<HTTP::Message::Headers:0x007f8d5356fda0 @http_version="1.1", @body_size=0, @chunked=false, @request_method="POST", @request_uri=#<Addressable::URI:0x3fc6a61124c8 URI:https://www.googleapis.com/youtube/v3/liveBroadcasts?key=my-api-key&part=snippet>, @request_query=nil, @request_absolute_uri=nil, @status_code=401, @reason_phrase="Unauthorized", @body_type=nil, @body_charset=nil, @body_date=nil, @body_encoding=#<Encoding:UTF-8>, @is_request=false, @header_item=[["Vary", "Origin"], ["Vary", "X-Origin"], ["WWW-Authenticate", "Bearer realm=\"https://accounts.google.com/\""], ["Content-Type", "application/json; charset=UTF-8"], ["Content-Encoding", "gzip"], ["Date", "Thu, 15 Feb 2018 12:59:45 GMT"], ["Expires", "Thu, 15 Feb 2018 12:59:45 GMT"], ["Cache-Control", "private, max-age=0"], ["X-Content-Type-Options", "nosniff"], ["X-Frame-Options", "SAMEORIGIN"], ["X-XSS-Protection", "1; mode=block"], ["Server", "GSE"], ["Alt-Svc", "hq=\":443\"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=\":443\"; ma=2592000; v=\"41,39,38,37,35\""], ["Transfer-Encoding", "chunked"]], @dumped=false>, @peer_cert=#<OpenSSL::X509::Certificate: subject=#<OpenSSL::X509::Name:0x007f8d5247d290>, issuer=#<OpenSSL::X509::Name:0x007f8d5247d268>, serial=#<OpenSSL::BN:0x007f8d5247d240>, not_before=2018-01-30 08:56:10 UTC, not_after=2018-04-24 08:30:00 UTC>, @http_body=#<HTTP::Message::Body:0x007f8d5356fd28 @body="{\n \"error\": {\n \"errors\": [\n {\n \"domain\": \"global\",\n \"reason\": \"required\",\n \"message\": \"Login Required\",\n \"locationType\": \"header\",\n \"location\": \"Authorization\"\n }\n ],\n \"code\": 401,\n \"message\": \"Login Required\"\n }\n}\n", @size=0, @positions=nil, @chunk_size=nil>, @previous=nil>
Caught error Unauthorized
Error - #<Google::Apis::AuthorizationError: Unauthorized>
Retrying after authentication failure
Google::Apis::AuthorizationError: Unauthorized
I have done
- Added Youtube API V3 https://console.developers.google.com
- Enabled live streaming on my youtube account
Any idea why this error is occurring? Thank you