Elixir로 Youtube에 업로드
소개
내 프로젝트의 경우 .
올바른 OAuth 토큰을 얻기 위해 약간 애를 먹었고 google generated elixir library ...
현재 2022 Google 클라우드 인터페이스로 모든 단계를 자세히 설명했습니다.
엘릭서 코드용 github 저장소
구글 클라우드 플랫폼에서 설정
프로젝트 만들기
유튜브 API 활성화
검색창에
youtube api
를 입력한 다음 YouTube Data api v3를 클릭합니다.활성화하십시오.
oauth 동의 화면 설정
Oauth 동의 화면을 클릭하고 외부를 선택한 다음 만들기를 선택합니다.
필수 필드 앱 이름, 사용자 지원 이메일 및 이메일 주소를 채웁니다.
범위를 추가하거나 제거합니다.
youtube 및 youtube 업로드를 선택한 다음 업데이트합니다.
테스트 사용자 추가 이 사용자는 업로드하려는 YouTube 채널을 소유한 Google입니다.
자격 증명 만들기
자격 증명 만들기를 클릭한 다음 OAuth 클라이언트 ID를 클릭합니다.
웹 응용 프로그램을 선택하고 이름과 반환 URI를
https://developers.google.com/oauthplayground
로 채웁니다. 이것은 oauthplayground에서 갱신 토큰을 얻기 위해 필수입니다! 페이지를 열어두면 client_id
및 client_secret
가 필요합니다.Google Playground에서 새로고침 토큰 받기
oauthplayground으로 이동합니다.
화면 오른쪽에서 설정을 열고 클라이언트 ID와 클라이언트 암호를 입력합니다.
왼쪽에서 youtube 및 youtube.upload를 선택한 다음 api 승인을 클릭하면 리디렉션되고 앱에 youtube 권한을 부여하라는 메시지가 표시됩니다.
이제 인증 코드를 토큰으로 교환을 클릭하십시오. 나중에 필요할 새로 고침 토큰을 복사하십시오.
엘릭서 코드
mix new --sup upload_with_elixir
cd upload_with_elixir
이러한 종속성을 다음 항목에 추가하십시오
mix.exs
....
{:goth, "~> 1.3-rc"},
{:hackney, "~> 1.17"},
{:google_api_you_tube, "~> 0.40"}
...
뎁 설치
mix deps.get
goth를 설정하도록 편집
application.ex
defmodule UploadWithElixir.Application do
use Application
def start(_type, _args) do
# I just put creds here in a real project you should use config
credentials = %{
# Fill it with your client id
"client_id" => "...",
# Fill it with your client secret
"client_secret" => "...",
# the token we got from the oauthplayground
"refresh_token" => "..."
}
source = {:refresh_token, credentials, []}
children = [
{Goth, name: UploadWithElixir.Goth, source: source}
]
Supervisor.start_link(children, strategy: :one_for_one)
end
end
goth로 토큰을 얻을 수 있는지 확인하십시오.
Goth.fetch(UploadWithElixir.Goth)
{:ok, %Goth.Token{ ... }}
google lib는 장황하므로 삽입을 수행하는 함수를 작성해 봅시다.
defmodule UploadWithElixir do
def video_insert do
# get the token
{:ok, token} = Goth.fetch(UploadWithElixir.Goth)
# set the token
conn = GoogleApi.YouTube.V3.Connection.new(token.token)
# The path to your video
video_path = Path.expand("./sample.webm", __DIR__)
# upload
GoogleApi.YouTube.V3.Api.Videos.youtube_videos_insert_simple(
conn,
["snippet", "status"],
"multipart",
%GoogleApi.YouTube.V3.Model.Video{
snippet: %GoogleApi.YouTube.V3.Model.VideoSnippet{
title: "Test Video upload from elixir",
description: "Description of the uploaded video"
},
status: %GoogleApi.YouTube.V3.Model.VideoStatus{
privacyStatus: "private"
}
},
video_path
)
end
end
iex를 시작하고 확인해야 하는 기능을 실행합니다.
UploadWithElixir.video_insert()
{:ok, %GoogleApi.YouTube.V3.Model.Video{ ... }}
작동하지 않는 경우.
10,000 할당량 할당과 업로드 비용 1600이 있습니다. 따라서 작동하지 않으면 모든 것을 다시 확인하십시오. 실패 요청 비용이 1600이더라도 24시간당 업로드 요청을 6번만 할 수 있습니다.
몇 가지 제한 사항:
Reference
이 문제에 관하여(Elixir로 Youtube에 업로드), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/mrdotb/upload-on-youtube-with-elixir-2ebm텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)