Bulk reports

Retrieve reports

This code sample demonstrates how to retrieve reports created by a specific job. It calls the jobs.list method to retrieve reporting jobs. It then calls the reports.list method with the jobId parameter set to a specific job id to retrieve reports created by that job. Finally, the sample prints out the download URL for each report.

Create a reporting job

This code sample demonstrates how to create a reporting job. It calls the reportTypes.list method to retrieve a list of available report types. It then calls the jobs.create method to create a new reporting job.

Targeted query reports

Retrieve daily channel statistics

This example calls the YouTube Analytics API to retrieve daily views and other metrics for the authorizing user's channel for the 2017 calendar year. The sample uses the Google APIs Python client library.

The code requests the user's permission to access the https://www.googleapis.com/auth/yt-analytics.readonly scope.

SCOPES = ['https://www.googleapis.com/auth/yt-analytics.readonly']

Your application might also need to request access to other scopes. For example, an application that calls the YouTube Analytics API and the YouTube Data API might need users to also grant access to their YouTube accounts. The authorization overview identifies scopes typically used in applications that call the YouTube Analytics API.

Set up authorization credentials

Before running this sample locally for the first time, you need to set up authorization credentials for your project:

Run the code

In the sample, update the value of the CLIENT_SECRETS_FILE variable to match the location of the file that you downloaded after setting up your authorization credentials.

Run the sample code in a terminal window:

python yt_analytics_v2.py

Go through the authorization flow. The auth flow might automatically load in your browser, or you might need to copy the auth URL into a browser window. At the end of the authorization flow, if necessary, paste the authorization code displayed in the browser into your terminal window and click [return].

The API query executes and the JSON response is output to the terminal window.