Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

What should I add to the ID parameter in Youtube Analytics API to get information from all the video in the world?

$
0
0

I am trying to get the Top 100 Most Viewed Youtube video when given a country(e.g US). When I was researching on google I found that I need to use these parameters:

dimensions=video

metrics=views,estimatedMinutesWatched,likes,subscribersGained

filters=continent==150 maxResults=10 sort=-views

Although it doesn't mention anything about what to add for id.

I already tried to directly remove the ID tag(or change it to global), although I get this error:

Traceback (most recent call last): File "/Users/aaravsharma/PycharmProjects/YouTube Analytics Project/main.py", line 33, in. <module> execute_api_request( File "/Users/aaravsharma/PycharmProjects/YouTube Analytics Project/main.py", line 23, in execute_api_request ).execute() ^^^^^^^^^ File "/Users/aaravsharma/PycharmProjects/YouTube Analytics Project/.venv/lib/python3.11/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper return wrapped(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/aaravsharma/PycharmProjects/YouTube Analytics Project/.venv/lib/python3.11/site-packages/googleapiclient/http.py", line 938, in execute raise HttpError(resp, content, uri=self.uri) googleapiclient.errors.HttpError: <HttpError 400 when requesting https://youtubeanalytics.googleapis.com/v2/reports?startDate=2017-01-01&endDate=2017-12- 31&metrics=estimatedMinutesWatched%2Cviews%2Clikes%2CsubscribersGained&dimensions=day&sort=day&al. t=json returned "Required". Details: "[{'message': 'Required', 'domain': 'global', 'reason': 'required'}]">

Does anyone know a parameter to add to the ID so I can get the world wide statistics?

The code I am using is here:

`# -- coding: utf-8 --

import osimport google.oauth2.credentialsimport google_auth_oauthlib.flowfrom googleapiclient.discovery import buildfrom googleapiclient.errors import HttpErrorfrom google_auth_oauthlib.flow import InstalledAppFlowSCOPES = ['https://www.googleapis.com/auth/yt-analytics.readonly']API_SERVICE_NAME = 'youtubeAnalytics'API_VERSION = 'v2'CLIENT_SECRETS_FILE = 'client_secret_73871116739-            tb1crfu00qsqg0i8n244l412pgab58p4.apps.googleusercontent.com.json'def get_service():  flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES)  credentials = flow.run_local_server(port=0)  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__':  # Disable OAuthlib's HTTPs verification when running locally.  # *DO NOT* leave this option enabled when running in production.  os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'  youtubeAnalytics = get_service()  execute_api_request(      youtubeAnalytics.reports().query,      ids='channel==MINE',      startDate='2017-01-01',      vvendDate='2017-12-31',      metrics='estimatedMinutesWatched,views,likes,subscribersGained',      dimensions='day',      sort='day'  )`

Please provide any support to get the statistics for the 100 viewed in a country(e.g US).

Some useful links that may help are below:. https://developers.google.com/youtube/analytics/channel_reports#geographic-reports https://developers.google.com/youtube/analytics/sample-requests#channel-geographic-reports https://developers.google.com/youtube/analytics/reference/reports/query? apix=true&apix_params=%7B%22metrics%22%3A%22estimatedMinutesWatched%2Cviews%2Clikes%2CsubscribersGained%22%2C%22dimensions%22%3A%22video%22%2C%22maxResults%22%3A%2210%22%2C%22sort%22%3A%22-estimatedMinutesWatched%22%2C%22startDate%22%3A%222023-01-01%22%2C%22endDate%22%3A%222023-06-30%22%2C%22ids%22%3A%22channel%3D%3DMINE%22%7D#python

Note - I am using the Youtube Analytics API in the Python Programming Language.

Thanks for your help in Advance!


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>