前提・実現したいこと
YouTube_Data_API_V3のCaptions.downloadで字幕を取得したいです。
OAuth2.0認証・Caption_IDの取得まではできたのですが、このCaption_IDを使ってCaptions.downloadを叩いた際に以下のエラーが発生しました
発生している問題・エラーメッセージ
'The permissions associated with the request are not sufficient to download the caption track. The request might not be properly authorized, or the video order might not have enabled third-party contributions for this caption.'
入力した動画IDに該当する動画の字幕に対しての権限がないのでこのエラーが起きたと認識しています(403エラーに当たる)
確かにこの動画はお借りしてきた動画でしたので、自身が投稿しているわけではなくこのようなエラーが出てしまうのは尤もなことだと思います。
しかし、以下の一文が気になります。
...or the video order might not have enabled third-party contributions for this caption.
この文章を読む限りだと、もし動画投稿者さんが外部からの字幕の権限を許可していればちゃんと動くのではと思いました。
そこで、この403エラーを回避するために、
事前に動画投稿者が字幕への権限の許可をしているのかどうかを確認できないのかをお聞きしたいです。
具体的には以下のようなことは出来ないでしょうか?
①ユーザ側が動画を選択する前にYouTubeの動画ページから字幕権限の許可を出している動画なのかどうかを確認できる。
②YouTube_Data_APIを用いて字幕権限の許可を出している動画なのか確認できる。
①のように、プログラム側からどうにかしなくても構わないです。何か方法やヒントがありましたら教えていただきたいです。よろしくお願いします。
該当のソースコード
Python
1import httplib2 2from oauth2client import tools 3from oauth2client import client 4from oauth2client.file import Storage 5import json 6 7youtubeURL = 'youtubeのリンク' 8 9 10def captionsIDGet(): 11 print("取得した動画ID:" + youtubeURL[-11:]) 12 videoID = youtubeURL[-11:] 13 14 credentials_path = "./credentials.json" 15 store = Storage(credentials_path) 16 credentials = store.get() 17 18 if credentials is None or credentials.invalid: 19 f = "./test_client.json" 20 scope = "https://www.googleapis.com/auth/youtube.force-ssl" 21 flow = client.flow_from_clientsecrets(f, scope) 22 flow.user_agent = "APIキー" 23 credentials = tools.run_flow(flow, Storage(credentials_path)) 24 25 http = credentials.authorize(httplib2.Http()) 26 url = "https://www.googleapis.com/youtube/v3/captions?part=snippet&videoId=" 27 url += videoID 28 29 res, data = http.request(url) 30 data = json.loads(data.decode()) 31 print(data) 32 33 captions_id = [] 34 for item in data["items"]: 35 try: 36 captions_id.append(item["id"]) 37 print(item["id"]) 38 except: 39 print("captionIDの取得に失敗しました") 40 41 captionGet(data, url, http, captions_id) 42 43 44def captionGet(data, url, http, captions_id): 45 url = "https://www.googleapis.com/youtube/v3/captions/" 46 url += captions_id[0] 47 48 res, data = http.request(url) 49 print(data)#ここで上記のエラーが出る 50 51 52if __name__ == '__main__': 53 captionsIDGet() 54
試したこと
・類似の問題を解決していそうな記事を探しましたが、見つかりませんでした。
・search.listから字幕の有無を確認することは出来るという情報を得ました。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。