Download channelDataExtraction.py from Collegitestech/Youtube-analytics-dashboard: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/spaces/Collegitestech/Youtube-analytics-dashboard/resolve/main/channelDataExtraction.py
- Command line
-
hf download hf://spaces/Collegitestech/Youtube-analytics-dashboard/channelDataExtraction.py
-
curl -L -o channelDataExtraction.py https://huggingface.co/spaces/Collegitestech/Youtube-analytics-dashboard/resolve/main/channelDataExtraction.py
1.29 kB
| 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) | |