##前提・実現したいこと
YouTube Data API v3を使って、データを取得したいと考えています。
search.listでデータを取得できましたが、次にvideos.listを使って、search.listで得た動画の再生回数などの情報をまとめて取得する方法を教えてください。
現状はsearch.listで得た動画のvideoIdを1個ずつ入力して情報を取得できますが、これをまとめて取得する方法がわかりません。
参考にした記事があるのですが、よくわからなかったので質問しました。
よろしくお願いします。
##該当のソースコード
from googleapiclient.discovery import build import pandas as pd YOUTUBE_API_KEY = 'APIキーは伏せておきます' youtube = build('youtube', 'v3', developerKey=YOUTUBE_API_KEY) def get_video_info(part,q,order,type,regionCode,maxResults): search_response = youtube.search().list( part=part, q=q, order=order, type=type, regionCode=regionCode, maxResults=maxResults ) response = search_response.execute() results = response['items'] keys = [] for i in results: key = i keys.append(key) df = pd.DataFrame(keys) df1 = pd.DataFrame(list(df['id']))['videoId'] df2 = pd.DataFrame(list(df['snippet']))[['channelTitle','publishedAt','channelId','title','description']] df3 = pd.concat([df1,df2], axis =1) df3.to_csv('鬼滅の刃.csv',index=False) get_video_info(part='snippet',q='鬼滅の刃',order='rating',type='video',regionCode='JP',maxResults='5') videos_response = youtube.videos().list( part='statistics', #現状は、search.listで得た動画のvideoIdを1個ずつ入力しています。 id='_f7dv40gVMQ' ) response = videos_response.execute() results = response['items'][0] print(results)
##補足情報(FW/ツールのバージョンなど)
参考
Youtube Data APIを使ってPythonでYoutubeデータを取得する
PythonとYoutube Data API(v3)で再生数を取得する
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2020/05/25 23:18 編集