My goal is to allow users of my application to upload my YouTube account through my server. I have a developer account with youtube api data enabled and setting up a service account client, and for some reason I have not logged in. I broke through the network, trying to understand why and found a lot of things. I tried to grant permissions in administrator security settings with identifiers and project scope. Many people said that this error was caused by the fact that I do not have a YouTube account associated with my account. but I don’t know how to knit them.
This is my upload_video.rb script:
require 'rubygems' require 'google/api_client' require 'google/api_client/client_secrets' require 'google/api_client/auth/file_storage' require 'google/api_client/auth/installed_app' require 'certified' DEVELOPER_KEY = "MY-DEVELOPER-KEY" YOUTUBE_UPLOAD_SCOPE = 'https://www.googleapis.com/auth/youtube.upload' YOUTUBE_API_SERVICE_NAME = 'youtube' YOUTUBE_API_VERSION = 'v3' def get_authenticated_service puts @PROGRAM_NAME client = Google::APIClient.new( :application_name => $PROGRAM_NAME, :application_version => '1.0.0' ) key = Google::APIClient::KeyUtils.load_from_pkcs12('oauth2service.p12', 'notasecret') auth_client = Signet::OAuth2::Client.new( :token_credential_uri => 'https://accounts.google.com/o/oauth2/token', :audience => 'https://accounts.google.com/o/oauth2/token', :scope => YOUTUBE_UPLOAD_SCOPE, :issuer => 'SERVICE ACCOUNT EMAIL ADDRESS', :signing_key => key) auth_client.fetch_access_token! client.authorization = auth_client youtube = client.discovered_api(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION) return client, youtube end def upload2youtube file, title, description, category_id, keywords, privacy_status client, youtube = get_authenticated_service begin body = { :snippet => { :title => title, :description => description, :tags => keywords.split(','), :categoryId => category_id, }, :status => { :privacyStatus => privacy_status } } videos_insert_response = client.execute!( :api_method => youtube.videos.insert, :body_object => body, :media => Google::APIClient::UploadIO.new(file, 'video/*'), :parameters => { :uploadType => 'resumable', :part => body.keys.join(',') } ) videos_insert_response.resumable_upload.send_all(client) puts "Video id '#{videos_insert_response.data.id}' was successfully uploaded." rescue Google::APIClient::TransmissionError => e puts e.result.body end end
This is how I run it from another script:
require 'google/api_client' require_relative 'upload_video' $PROGRAM_NAME = 'MY-PROJECT-NAME' upload2youtube File.open("somevideo.avi"), "title", "description", 'categoryid', 'tag1,tag2,tag3', 'unlisted'
And this is the result:
{ "error": { "errors": [ { "domain": "youtube.header", "reason": "youtubeSignupRequired", "message": "Unauthorized", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Unauthorized" } }
What am I doing wrong