-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannelDataExtraction.py
36 lines (27 loc) · 1.25 KB
/
channelDataExtraction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import googleapiclient.discovery
def getChannelData(api_key, channel_id):
try:
# Create a YouTube API object
youtube = googleapiclient.discovery.build("youtube",
"v3",
developerKey=api_key)
# request channel details
request = youtube.channels().list(part="snippet,contentDetails,statistics",
id=channel_id)
response = request.execute()
# Get the channel details from the response
channel = response["items"][0]
# channel details dictionary
channel_details = {
"title": channel["snippet"]["title"],
"description": channel["snippet"]["description"],
"viewCount": channel["statistics"]["viewCount"],
"subscriberCount": channel["statistics"]["subscriberCount"],
"uploads": channel['contentDetails']['relatedPlaylists']['uploads'],
"thumbnail": channel['snippet']['thumbnails']['medium']['url']
}
print(channel_details)
return channel_details
except Exception as error:
return None
#getChannelData(api_key, channel_id)