Prerequisites
Before proceeding, ensure the following prerequisites are met:- Install MindsDB on your system or obtain access to cloud options.
- To use YouTube with MindsDB, install the required dependencies following this instruction.
Connection
There are two ways you can connect YouTube to MindsDB:- Limited permissions: This option provides MindsDB with read-only access to YouTube, including viewing comments data.
- Elevated permissions: This optiona provides MindsDB with full access to YouTube, including viewing comments data and posting replies to comments.
Option 1: Limited permissions
Establish a connection to YouTube from MindsDB by executing the below SQL command and following the Google authorization link provided as output:youtube_api_token: It is a Google API key used for authentication. Check out this guide on how to create the API key to access YouTube data.
Option 2: Elevated permissions
Establish a connection to YouTube from MindsDB by executing the below SQL command and following the Google authorization link provided as output:credentials_file: It is a path to a file generated from the Google Cloud Console, as described below.credentials_url: It is a URL to a file generated from the Google Cloud Console, as described below.
How to Generate the Credentials File
How to Generate the Credentials File
- Open the Google Cloud Console.
- Create a new project.
-
Inside this project, go to APIs & Services:
-
Go to Enabled APIs & services:
- Click on ENABLE APIS AND SERVICES from the top bar.
- Search for YouTube Data API v3 and enable it.
-
Go to OAuth consent screen:
- Choose user type as External and click on Create.
- Provide app name and support email.
- In Scopes, add the following scopes:
../auth/youtube,.../auth/youtube.force-ssl,.../auth/youtubepartner. - Next, add test users.
- Save and continue.
-
Go to Credentials:
- Click on CREATE CREDENTIALS from the top bar and choose OAuth client ID.
- Choose type as
Web applicationand provide a name. In the Authorized redirect URIs, add the following:http://localhost/verify-auth,https://cloud.mindsdb.com/verify-auth,http://127.0.0.1:47334/verify-auth - Click on CREATE.
- Download the JSON file that is required to connect YouTube to MindsDB.
-
Go to Enabled APIs & services:
Usage
Use the established connection to query thecomments table.
You can query for one video’s comments:
channels table.
channel_id column is mandatory in the WHERE clause.
Use the established connection to query the videos table.
video_id column is mandatory in the WHERE clause.
With the connection option 2, you can insert replies to comments: