Welcome to the "How to get trending videos for a specific keyword via YouTube API" template. This guide will walk you through the process of using this Lazy template to create an application that fetches trending videos from YouTube based on user-provided keywords. The application leverages the YouTube Data API v3 and is designed to be simple to use, even for non-technical builders.
To begin, click on the "Start with this Template" button. This will initialize the template in the Lazy Builder interface, pre-populating the code necessary for the application.
Before testing the application, you need to set up an environment secret for the YouTube API key. Here's how to obtain and set up your YouTube API key:
Once the environment secret is set, press the "Test" button. This will deploy the application and launch the Lazy CLI. You will be provided with a server link to interact with the API.
If the application requires user input, the Lazy CLI will prompt you for it after pressing the test button. For this template, you will be asked to provide keywords for which you want to find trending YouTube videos.
After deployment, you can use the provided server link to send requests to the API. Additionally, you will receive a link to the FastAPI documentation (`/docs`) where you can test the API endpoints directly from your browser.
Here's a sample request to the `/trending/` endpoint:
POST /trending/
Content-Type: application/json
{
"keywords": "music"
}
And a sample response might look like this:
[
{
"title": "Trending Music Video",
"description": "Latest trending music video on YouTube",
"videoUrl": "https://www.youtube.com/watch?v=example"
// ... other video details
}
// ... more videos
]
If you wish to integrate this application with an external tool or service, you will need to use the server link provided by Lazy. For instance, you can add the API endpoint to a frontend application to display trending videos based on user input. Ensure that you handle the API key securely and do not expose it in the frontend.
For further integration, such as adding the app's server link in an external tool, follow the specific instructions provided by that tool for adding external API endpoints.
By following these steps, you should now have a fully functional application that can fetch trending YouTube videos based on keywords. Enjoy building with Lazy!