To fetch data from youtube using the youtube_analytics_report.query api. This project has the code sample (in python) to pull data from the api. The code sample can be edited to suit needs like dimensions and metrics. There is also and EXE available for windows users to pull core metrics and dimensions from youtube api. All tou need is to set up the credentials as explained below.
Check here to find out more Youtube API docs
Before running this sample locally for the first time, you need to set up authorization credentials for your project:
- Create or select a project in the Google API Console.
- Enable the YouTube Analytics API for your project.
- At the top of the Credentials page, select the OAuth consent screen tab. Select an Email address, enter a Product name if not already set, and click the Save button.
- On the Credentials page, click the Create credentials button and select Oauth client ID.
- Select the application type Other, enter the name "YouTube Analytics API Quickstart", and click the Create button.
- Click OK to dismiss the resulting dialog.
- Click the file_download (Download JSON) button to the right of the client ID.
- Move the downloaded file to your working directory.
- double click ytapi.exe to run the application
-
Python 2.6 or greater(get here: https://python.org/downloads)
-
The pip package management tool
-
The Google APIs Client Library for Python:
pip install --upgrade google-api-python-client
-
The google-auth, google-auth-oauthlib, and google-auth-httplib2 for user authorization.
pip install --upgrade google-auth google-auth-oauthlib google-auth-httplib2
Now, you are ready to actually test the sample:
-
Copy the code sample below to your working directory. 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 ytapi.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 written as an output.json and csv file.