I want to get the top youtube search terms for a specific video from traffic source but unable to get it through youtube analytics api?Here is my code:
import csvfrom googleapiclient.discovery import buildfrom google_auth_oauthlib.flow import InstalledAppFlowfrom tabulate import tabulateSCOPES = ['https://www.googleapis.com/auth/yt-analytics.readonly']API_SERVICE_NAME = 'youtubeAnalytics'API_VERSION = 'v2'CLIENT_SECRETS_FILE = 'yt_credentials.json'def get_service(): flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES)# credentials = flow.run_console() # alternatively (https://github.com/onlyphantom/youtube_api_python/pull/3/files): credentials = flow.run_local_server() return build(API_SERVICE_NAME, API_VERSION, credentials = credentials)def execute_api_request(client_library_function, **kwargs): response = client_library_function( **kwargs ).execute() return responseif __name__ == '__main__': video_id = "txnSq7wlxjU" youtubeAnalytics = get_service() result = execute_api_request( youtubeAnalytics.reports().query, ids='channel==MINE', filters=f'video=={video_id}, ', startDate='2023-02-20', endDate='2023-03-30', metrics='views, yt_search', dimensions='insightTrafficSourceDetail', ) print(result)
I wanted to get the top youtube search terms for specific video and sort them based on views.