1
내 목표는 내 앱 사용자가 내 서버를 통해 내 YouTube 계정에 업로드하도록하는 것입니다. YouTube 데이터 API를 사용하도록 설정하고 서비스 계정 클라이언트를 설정하고 개발자 권한을 보유하고 있으며 어떤 이유로 승인되지 않았습니다. 나는 그물을 통해 왜 그려 냈는지 알아 냈고, 많은 것을 발견했다. 프로젝트 클라이언트 ID 및 범위를 사용하여 관리자 보안 설정에 권한을 부여하려고 시도했습니다. 많은 사람들이 내 계정과 연결된 YouTube 계정이 없기 때문에이 오류가 발생했다고 말하고있었습니다. 그러나 나는 이것들을 연관시키는 방법을 모른다.동영상 삽입 방법 Ruby를 사용하여 서비스 계정을 통해 api v3을
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
이 내가 다른 스크립트를 실행하고 방법은 다음과 같습니다 :
이
내 upload_video.rb 스크립트입니다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'
그리고 이것은 결과입니다
{
"error": {
"errors": [
{
"domain": "youtube.header",
"reason": "youtubeSignupRequired",
"message": "Unauthorized",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Unauthorized"
}
}
내가 뭘 잘못하고 있니?
받는 중 Signet :: AuthorizationError : 인증에 실패했습니다. 서버 메시지 : { "오류": "invalid_grant" } – venkatareddy
코드를 업데이트했습니다. 지금 시도하십시오. – dangalg
@venkatareddy 코드를 지금 사용해 보셨습니까? 나는 그것을 편집했다. 죄송합니다. – dangalg