My company has a content owner youtube account. My own google account is linked to this content owner account and I have management privileges. I can log into the CMS and view analytics data for youtube channels that are linked to our content owner account. Via the APIs however I am experiencing some inconsistent exceptions: For the Reporting API I am fine - I can successfully request and download content owner reports on our linked channels no problem. But with the same credentials (same client ID, different scopes / oauth token) I cannot make targeted queries against channels linked to our content owner account (the Analytics API).
I can however make targeted queries against our own channel (i.e. channel==MINE), just not other linked channels. Why is this happening? I have the correct privileges and the correct scopes as far as I can tell.
Here is an example of a request written in python using their client:
import osfrom googleapiclient.discovery import buildfrom google_auth_oauthlib.flow import InstalledAppFlowSCOPES = ['https://www.googleapis.com/auth/yt-analytics-monetary.readonly', 'https://www.googleapis.com/auth/yt-analytics.readonly','https://www.googleapis.com/auth/youtube', 'https://www.googleapis.com/auth/youtubepartner','https://www.googleapis.com/auth/youtube.readonly']API_SERVICE_NAME = 'youtubeAnalytics'API_VERSION = 'v2'CLIENT_SECRETS_FILE = '<client_secret_file-youtube.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='contentOwner==<contentowner_id>', filters='channel==<channel_id>', startDate='2019-01-01', endDate='2019-03-01', metrics='subscribersGained', dimensions='month', sort='month' )and here is the response I receive:
HttpError: <HttpError 403 when requesting https://youtubeanalytics.googleapis.com/v2/reports?ids=contentOwner%3D%3D<contentowner_id>&filters=channel%3D%3D<channel_id>&startDate=2019-01-01&endDate=2019-03-01&metrics=subscribersGained&dimensions=month&sort=month&alt=json returned "Forbidden". Details: "[{'message': 'Forbidden', 'domain': 'global', 'reason': 'forbidden'}]">