I am trying to pull retention data for my videos.
I am able to access the title, description and total views but when I try to pull up retention data, the API returns 0 rows.
I can use the same information and pull up other time based datasets like Daily Watch time without any issues.
I've tried to do this two ways.
Using the online query tools found here: https://developers.google.com/youtube/analytics/reference/reports/query
Building my own python script
from google.oauth2.credentials import Credentialsfrom googleapiclient.discovery import buildfrom googleapiclient.errors import HttpErrorimport json# Access InfoACCESS_TOKEN = 'Blah'VIDEO_ID = 'Blah'CLIENT_ID = 'Blah'CLIENT_SECRET = 'Blah'def get_video_info(youtube_data, video_id):response = youtube_data.videos().list(part='snippet',id=video_id).execute() if response.get('items'): video = response['items'][0] title = video['snippet']['title'] print(f'Video Title: {title}') return video else: print('Video not found') return Nonedef get_retention_data(access_token, video_id, client_id, client_secret):try:\# Build the YouTube Analytics API clientcredentials = Credentials(access_token, client_id=client_id, client_secret=client_secret)print("Credentials:", credentials)youtube_analytics = build('youtubeAnalytics', 'v2', credentials=credentials)youtube_data = build('youtube', 'v3', credentials=credentials) # Fetch the video info video_info = get_video_info(youtube_data, VIDEO_ID) # Set the required parameters for the API call start_date = '2023-04-10' end_date = '2023-04-12' metrics = 'relativeRetentionPerformance' dimensions = 'elapsedVideoTimeRatio' # Build the API request request = youtube_analytics.reports().query( ids='channel==MINE', startDate=start_date, endDate=end_date, metrics=metrics, dimensions=dimensions, filters=f'video=={video_id}' ) # Print the API request URL print("API Request URL:", request.to_json()) # Execute the API request response = request.execute() # Print the response print("API Response:") print(json.dumps(response, indent=2)) except HttpError as e: print(f'An error occurred: {e}') response = None return responsedef save_retention_data_to_file(data, filename='retention_data.json'):with open(filename, 'w') as f:json.dump(data, f, indent=2)print(f'Retention data saved to {filename}')# Call the function to get the retention dataretention_data = get_retention_data(ACCESS_TOKEN, VIDEO_ID, CLIENT_ID, CLIENT_SECRET)# Save the retention data to a filesave_retention_data_to_file(retention_data)With both methods, I can access the video information but not the retention data. I've tried this across multiple videos with retention data and the end result is still the same.