Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 185eb74

Browse files
Merge pull request avinashkranjan#2705 from Shivansh-Jain-github/gssoc1
Youtube API python code
2 parents 0407307 + 958589e commit 185eb74

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

‎Youtube API/README.md‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# YouTube API Video Search Example
2+
3+
This repository provides a simple Python script that demonstrates how to use the YouTube API to search for videos based on a query. The script fetches video details such as titles and video IDs from the search results.
4+
5+
## Prerequisites
6+
7+
- Python 3.x
8+
- Install the `google-api-python-client` library using the following command:
9+
10+
```bash
11+
pip install google-api-python-client
12+
```
13+
14+
## Getting Started
15+
16+
1. Clone this repository to your local machine:
17+
18+
```bash
19+
git clone https://github.com/your-username/youtube-api-search.git
20+
```
21+
22+
2. Navigate to the repository's directory:
23+
24+
```bash
25+
cd youtube-api-search
26+
```
27+
28+
3. Replace `'YOUR_API_KEY'` with your actual YouTube API key in the `script.py` file.
29+
30+
4. Run the script using your Python interpreter:
31+
32+
```bash
33+
python script.py
34+
```
35+
36+
## Usage
37+
38+
The `script.py` file in this repository contains the sample code to search for videos using the YouTube API. The script performs the following steps:
39+
40+
1. Imports the necessary libraries.
41+
2. Initializes the YouTube API client with your API key.
42+
3. Defines a search query.
43+
4. Calls the `search.list` method to retrieve search results for videos.
44+
5. Prints video information (title and video ID) from the search results.
45+
46+
The script can be easily customized for your use case, allowing you to explore more YouTube API features.
47+
48+
## Example Output
49+
50+
```
51+
Video Title: Python Programming Tutorial - 1 | Python Tutorial For Beginners | Python Training | Edureka
52+
Video ID: WGJJIrtnfpk
53+
------------------------------
54+
Video Title: Python Tutorial for Beginners [Full Course] 2019
55+
Video ID: HBxCHonP6Ro
56+
------------------------------
57+
...
58+
```
59+
60+
## Important Note
61+
62+
Please ensure that you handle your API keys securely and follow YouTube's API terms of service and usage guidelines. This example provides a starting point for using the YouTube API for video searches.
63+
64+
For more detailed information about the YouTube Data API and its capabilities, refer to the [official documentation](https://developers.google.com/youtube/v3).
65+

‎Youtube API/script.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from googleapiclient.discovery import build
2+
3+
# Replace 'YOUR_API_KEY' with your actual API key
4+
api_key = 'YOUR_API_KEY'
5+
6+
# Create a YouTube API client
7+
youtube = build('youtube', 'v3', developerKey=api_key)
8+
9+
# Define the search query
10+
search_query = 'python programming tutorial'
11+
12+
# Call the search.list method to retrieve search results
13+
search_response = youtube.search().list(
14+
q=search_query,
15+
type='video',
16+
part='id,snippet',
17+
maxResults=10
18+
).execute()
19+
20+
# Print video information from the search results
21+
for item in search_response['items']:
22+
video_title = item['snippet']['title']
23+
video_id = item['id']['videoId']
24+
print(f"Video Title: {video_title}")
25+
print(f"Video ID: {video_id}")
26+
print("------------------------------")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /