Скрипт поиска каналов Ютуб
Вот код:
from googleapiclient.discovery import build
from datetime import datetime, timedelta
# Установка ключа API и создание экземпляра объекта youtube
api_key = "***"
youtube = build('youtube', 'v3', developerKey=api_key)
# Функция для поиска каналов
def search_channels(query, min_subscriber_count=0, published_after=None):
# Определение параметров запроса
query_params = {
'q': query,
'type': 'channel',
'part': 'id,snippet',
'maxResults': 10,
'order': 'relevance'
}
# Добавление параметров фильтрации
if min_subscriber_count > 0:
query_params['minSubscriberCount'] = min_subscriber_count
if published_after is not None:
query_params['publishedAfter'] = published_after
# Выполнение запроса
request = youtube.search().list(**query_params)
response = request.execute()
channels = []
# Обработка результатов
for item in response['items']:
channel = {
'id': item['id']['channelId'],
'title': item['snippet']['title'],
'description': item['snippet']['description'],
'published_at': item['snippet']['publishedAt'],
'thumbnail': item['snippet']['thumbnails']['default']['url'],
'subscriber_count': 0
}
# Получение информации о количестве подписчиков
statistics = youtube.channels().list(
part='statistics',
id=channel['id']
).execute()
if statistics['items']:
channel['subscriber_count'] = int(statistics['items'][0]['statistics']['subscriberCount'])
channels.append(channel)
return channels
# Пример использования функции search_channels
six_months_ago = (datetime.utcnow() - timedelta(days=180)).strftime('%Y-%m-%dT%H:%M:%SZ')
channels = search_channels('python', min_subscriber_count=50000, published_after=six_months_ago)
for channel in channels:
print(f"{channel['title']} ({channel['subscriber_count']} подписчиков)")
Выдает ошибку:
File "C:\Users\Puzyrin\PycharmProjects\pythonProject1\venv\Lib\site-packages\googleapiclient\discovery.py", line 1048, in method
raise TypeError("Got an unexpected keyword argument {}".format(name))
TypeError: Got an unexpected keyword argument minSubscriberCount
Помогите пожалуйста с именами в апи.
Источник: Stack Overflow на русском