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

Do I need to publish my youtube_analytics_api app for VERIFICATION in GCP to get access to monetary information for my YT channel?

$
0
0

I am trying to use the Youtube Analytics API to get monthly analytics regarding my channel performance. According to this url, it lists a variety of Metrics I have access to including things like estimatedMinutesWatched, views, likes, subscribersGained, estimatedRevenue, and etc. When I make the api call specifying these metrics estimatedMinutesWatched, views, likes, subscribersGained I get a valid response and I can see the metrics breakdown based on the day. However when I add the metric estimatedRevenue, it gets me the following error:

Traceback (most recent call last):  File "C:\Users\ayubs\OneDrive\Desktop\youtube-analytics\youtube_analytics_api_monthly_stats.py", line 104, in <module>    execute_api_request(  File "C:\Users\ayubs\OneDrive\Desktop\youtube-analytics\youtube_analytics_api_monthly_stats.py", line 92, in execute_api_request    response = client_library_function(  File "C:\Python\Python39\lib\site-packages\googleapiclient\_helpers.py", line 130, in positional_wrapper    return wrapped(*args, **kwargs)  File "C:\Python\Python39\lib\site-packages\googleapiclient\http.py", line 840, in execute    raise HttpError(resp, content, uri=self.uri)googleapiclient.errors.HttpError: <HttpError 403 when requesting https://youtubeanalytics.googleapis.com/v2/reports?ids=channel%3D%3DMINE&startDate=2022-01-30&endDate=2022-02-15&metrics=estimatedMinutesWatched%2Cviews%2Clikes%2CsubscribersGained%2CestimatedRevenue&dimensions=day&sort=day&alt=json returned "Forbidden">

Here is how I am making the call, I downloaded my OAuth 2.0 Client IDs credentials which is stored in a json from GCP. I am importing those in my code which upon execution asks me to login to my email/youtube account.

I have pasted a copy of the code below:

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','https://www.googleapis.com/auth/yt-analytics-monetary.readonly','https://www.googleapis.com/auth/youtube.readonly','https://www.googleapis.com/auth/youtube','https://www.googleapis.com/auth/youtubepartner'        ]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_console()  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='2022-01-30',      endDate='2022-02-15',      metrics='estimatedMinutesWatched,views,likes,subscribersGained,estimatedRevenue',      dimensions='day',      sort='day'  )

Perhaps I am going about this the wrong way? I just want to be able to pull monetary information regarding my channel whether that is related to ads or just estimatedRevenue.

the scopes I am using are the following and I have added these scopes in GCP:

[  '/auth/yt-analytics.readonly','/auth/yt-analytics-monetary.readonly','/auth/youtube.readonly','/auth/youtube','/auth/youtubepartner']

I know some of the functionality may be deprecated however I tried my best to use up to date API's if you see anything amiss, please guide. Thanks.


Viewing all articles
Browse latest Browse all 3831

Trending Articles



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