Another team owns a YouTube channel and I was invited as Viewer.
I can check analytics data through YouTube Studio.
Now I am struggling to download the data by using YouTube Analytics API.
The owner team provided me Client ID and Secret by enabling YouTube related APIs.
However I cannot access their channel data with Forbidden error.
I tried to download with following python code, but it returns “Forbidden”
Any suggestion/solution to download analytics data with Viewer permission?
SCOPES = ['https://www.googleapis.com/auth/yt-analytics.readonly',
'https://www.googleapis.com/auth/youtube.readonly']
API_SERVICE_NAME = 'youtubeAnalytics'
API_VERSION = 'v2'
CLIENT_SECRETS_FILE = 'client_secret.json'
def get_service():
flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES)
credentials = flow.run_local_server(port=8888)
return build(API_SERVICE_NAME, API_VERSION, credentials = credentials)
def execute_api_request(client_library_function, **kwargs):
response = client_library_function(
**kwargs
).execute()
print(response)
if __name__ == '__main__':
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
youtubeAnalytics = get_service()
execute_api_request(
youtubeAnalytics.reports().query,
ids='channel==UCxxxxxxxxxxxx',
startDate='2024-12-01',
endDate='2024-12-10',
metrics='estimatedMinutesWatched,views,likes,subscribersGained',
dimensions='day',
sort='day'
)
Koji Kunii is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.