I'm trying to produce a script that pulls the estimated watch time and watch percetage for one/some/all of my videos on my Youtube channel(s). I can get the below to run but it returns zeros as it only runs on my account which has no videos directly on it. The video are all on 'sub channels' (not sure that is the correct description, sorry). If I replace the Channel==MINE with Channnel= I get a 403 Error. I seem I have to have a Client_Secrets file specifically for the channel but on the Google Console I only have the option to generate one for my 'user account' rather than the channel. What am I doing wrong?
import os
import google.auth
from google.oauth2.credentials import Credentials
your text`from googleapiclient.discovery import build
your text`KEY_FILE_LOCATION = "dsom-support-96f68aeb0d13.json"
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
creds, project = google.auth.load_credentials_from_file(
KEY_FILE_LOCATION,
scopes=["https://www.googleapis.com/auth/yt-analytics.readonly", "https://www.googleapis.com/auth/youtube.readonly", "https://www.googleapis.com/auth/yt-analytics-monetary.readonly"]
)
youtube_analytics = build('youtubeAnalytics', 'v2', credentials=creds)
youtube = build('youtube', 'v3', credentials=creds)
response = youtube_analytics.reports().query(
ids="channel==MINE",
metrics="estimatedMinutesWatched,views,likes,subscribersGained",
startDate='2022-01-01',
endDate='2023-05-01'
).execute()
for row in response["rows"]:
print(row)