Why does Youtube API give me different results for some channels than they actually are?

I have a script that gets information from Youtube using their API and saves it to excel file.

The script runs normally for some channels and for some it does not, e.g. when I used it for BBC and CNN channel it got all of the information that it needed, but when I tried it on MrBeast or Tech With Tim channel, it only returned me 3 videos for MrBeast and 2 for Tech With Tim, even though both channels have more videos.

What could be the problem?

Here is the full code:

import pandas as pd
from googleapiclient.discovery import build

api_key = 'YOUR_API_KEY_HERE'  # Replace with your API key

youtube = build('youtube', 'v3', developerKey=api_key)

# Retrieve the channel ID for the given username
channel_request = youtube.channels().list(
    part='snippet,contentDetails',
    forUsername='BBCNews'
)
channel_response = channel_request.execute()

# Extract channel username and ID
channel_username = channel_response['items'][0]['snippet']['title']
channel_id = channel_response['items'][0]['id']

# Initialize variables for pagination
next_page_token = None
all_videos = []

# Retrieve all videos from the channel
while True:
    videos_request = youtube.search().list(
        part='snippet',
        channelId=channel_id,
        type='video',
        order='date',
        maxResults=50,  # Maximum results per page
        pageToken=next_page_token
    )
    videos_response = videos_request.execute()
    
    all_videos.extend(videos_response['items'])

    next_page_token = videos_response.get('nextPageToken')
    if not next_page_token:
        break  # Break the loop if there are no more pages

# Initialize lists to store extracted information
titles = []
published_dates = []
likes = []
views = []
descriptions = []
urls = []

# Extract information from each video
for video in all_videos:
    video_id = video['id']['videoId']
    video_title = video['snippet']['title']
    video_description = video['snippet']['description']
    video_published_at = video['snippet']['publishedAt']
    video_url = f'https://www.youtube.com/watch?v={video_id}'

    # Retrieve statistics for each video
    video_statistics_request = youtube.videos().list(
        part='statistics',
        id=video_id
    )
    video_statistics_response = video_statistics_request.execute()
    video_statistics = video_statistics_response['items'][0]['statistics']
    video_likes = int(video_statistics.get('likeCount', 0))
    video_views = int(video_statistics.get('viewCount', 0))

    # Append extracted information to lists
    titles.append(video_title)
    published_dates.append(video_published_at)
    likes.append(video_likes)
    views.append(video_views)
    descriptions.append(video_description)
    urls.append(video_url)

# Create a DataFrame from the lists
data = {
    'Title': titles,
    'Published Date': published_dates,
    'Likes': likes,
    'Views': views,
    'Description': descriptions,
    'URL': urls
}
df = pd.DataFrame(data)

# Save DataFrame to Excel file with channel username as filename
excel_file_path = f'{channel_username}_videos.xlsx' 
df.to_excel(excel_file_path, index=False)

print("Excel file saved successfully.")

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật