docs/integrations/app-integrations/youtube.mdx
In this section, we present how to connect YouTube to MindsDB.
YouTube is a popular online video-sharing platform and social media website where users can upload, view, share, and interact with videos created by individuals and organizations from around the world.
Before proceeding, ensure the following prerequisites are met:
There are two ways you can connect YouTube to MindsDB:
Establish a connection to YouTube from MindsDB by executing the below SQL command and following the Google authorization link provided as output:
CREATE DATABASE mindsdb_youtube
WITH ENGINE = 'youtube',
PARAMETERS = {
"youtube_api_token": "<your-youtube-api-key-token>"
};
To do that, click on the Add button, choose New Datasource, search for YouTube, and follow the instructions in the form. After providing the connection name and the YouTube API token, click on the Test Connection button. Once the connection is established, click on the Save and Continue button.
</Tip>
Required connection parameters include the following:
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.Establish a connection to YouTube from MindsDB by executing the below SQL command and following the Google authorization link provided as output:
CREATE DATABASE mindsdb_youtube
WITH ENGINE = 'youtube',
PARAMETERS = {
"credentials_file": "path-to-credentials-json-file"
-- alternatively, use the credentials_url parameter
};
To do that, click on the Add button, choose New Datasource, search for YouTube, and follow the instructions in the form. After providing the connection name and the credentials file or URL, click on the Test Connection button and complete the authorization process in the pop-up window. Once the connection is established, click on the Save and Continue button.
</Tip>
Required connection parameters include one of the following:
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.Open the Google Cloud Console.
Create a new project.
Inside this project, go to APIs & Services:
Go to Enabled APIs & services:
Go to OAuth consent screen:
Go to Credentials:
Web application and provide a name. Under Authorized redirect URIs, enter URL where MindsDB has been deployed followed by /verify-auth. For example, if you are running MindsDB locally (on https://localhost:47334), enter https://localhost:47334/verify-auth.Use the established connection to query the comments table.
You can query for one video's comments:
SELECT *
FROM mindsdb_youtube.comments
WHERE video_id = "raWFGQ20OfA";
Or for one channels's comments:
SELECT *
FROM mindsdb_youtube.comments
WHERE channel_id="UC-...";
You can include ordering and limiting the output data:
SELECT * FROM mindsdb_youtube.comments
WHERE video_id = "raWFGQ20OfA"
ORDER BY display_name ASC
LIMIT 5;
Use the established connection to query the channels table.
SELECT * FROM mindsdb_youtube.channels
WHERE channel_id="UC-...";
Here, the channel_id column is mandatory in the WHERE clause.
Use the established connection to query the videos table.
SELECT * FROM mindsdb_youtube.videos
WHERE video_id="id";
Here, the video_id column is mandatory in the WHERE clause.
With the connection option 2, you can insert replies to comments:
INSERT INTO mindsdb_youtube.comments (comment_id, reply)
VALUES ("comment_id", "reply message");