Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How Can I Fetch all the data from Youtube to the Google Big Query Using Data transfer Job Service

I want to fetch all the Youtube Post and Page Analytics from my Youtube Channel using the Data Transfer Job Available in the Google Big Query. How Can I fetch all the Histric Data and the Current Data aailable in the Youtube Channels? 

0 1 554
1 REPLY 1

Hi @shayansiddique If you’re looking to bring both historical and current YouTube channel data into BigQuery using the Data Transfer Service, here’s a straightforward guide to help you out:

1. Setting Up the YouTube Data Transfer in BigQuery

Google BigQuery’s Data Transfer Service (DTS) includes a connector for YouTube channel reports. Follow these steps:

  • Enable the YouTube Reporting API:

    • Open the Google Cloud Console, search for the YouTube Reporting API, and enable it for your project.
  • Create a Data Transfer Job in BigQuery:

    • Navigate to BigQuery in the Cloud Console.
    • Under the "Transfers" tab, click on "Create Transfer".
    • Choose YouTube Channel as the source.

Note on Historic Data:
The YouTube Reporting API can provide historical data using predefined report templates. However, this is subject to YouTube’s retention policies, which typically store data for a fixed period (e.g., up to 180 days for some reports).

2. Fetching Current and Real-Time Data

For real-time or more detailed data, you’ll need to use the YouTube Analytics API.

  • How to Fetch Real-Time Data:
    • Write a custom script (e.g., in Python) to extract metrics such as views, watch time, and audience demographics.
    • Upload the fetched data into BigQuery for analysis.

Here’s an example Python snippet:

 

from googleapiclient.discovery import build
 
# Authenticate and initialize the API client
youtube = build('youtubeAnalytics', 'v2', developerKey='YOUR_API_KEY')
 
# Fetch analytics data
response = youtube.reports().query(
ids='channel==MINE',
startDate='2023-01-01',
endDate='2023-12-31',
metrics='views,estimatedMinutesWatched',
dimensions='day',
).execute() print(response)

3. Combining Historical and Real-Time Data

To merge historical data from BigQuery transfers with real-time data fetched via the API:

  1. Export real-time data to BigQuery after fetching it through the API.
  2. Use SQL within BigQuery to combine datasets. For example:

 

SELECT * FROM `your_project.historic_data_table` UNION ALL SELECT * FROM `your_project.realtime_data_table`

4. Alternative Tools for YouTube Analytics

If managing APIs and setting up data pipelines sounds like a hassle, there are third-party tools that simplify the process:

  • Windsor.ai: This platform offers pre-built connectors that make it easy to bring YouTube Analytics data (both historical and current) into BigQuery. It eliminates the need for manual scripting and helps streamline your integration process.

Final Recommendations

  • Use the BigQuery Data Transfer Service for historical data, wherever available.
  • Rely on the YouTube Analytics API for more granular or real-time metrics.
  • Consider third-party tools like Windsor.ai if you want a smoother, less technical integration experience.