Reputation: 1
I am trying to get a list of all the 800+ youtube channels that I am subscribed to. It would be great if someone could provide a python sample for the same.
Yet to try the sample programs. But did have a look at youtube api.
Upvotes: 0
Views: 1452
Reputation: 5632
You are looking for YouTube Data API v3 Subscriptions: list endpoint. As it requires obtaining authorization credentials, have a look to this guide. If you want to proceed using OAuth 2, here is the Python code suggested by the API itself:
# -*- coding: utf-8 -*-
# Sample Python code for youtube.subscriptions.list
# See instructions for running these code samples locally:
# https://developers.google.com/explorer-help/code-samples#python
import os
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
scopes = ["https://www.googleapis.com/auth/youtube.readonly"]
def main():
# Disable OAuthlib's HTTPS verification when running locally.
# *DO NOT* leave this option enabled in production.
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
api_service_name = "youtube"
api_version = "v3"
client_secrets_file = "YOUR_CLIENT_SECRET_FILE.json"
# Get credentials and create an API client
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
client_secrets_file, scopes)
credentials = flow.run_console()
youtube = googleapiclient.discovery.build(
api_service_name, api_version, credentials=credentials)
request = youtube.subscriptions().list(
part="snippet,contentDetails",
mine=True
)
response = request.execute()
print(response)
if __name__ == "__main__":
main()
Otherwise if you just want to proceed with an API key, you can proceed this way with this Python code requiring the channel id you are retrieving subscriptions for:
import googleapiclient.discovery
youtube = googleapiclient.discovery.build(
"youtube", "v3", developerKey="AIzaSy...")
request = youtube.subscriptions().list(
part="snippet,contentDetails",
channelId="CHANNEL_ID"
)
response = request.execute()
print(response)
Upvotes: 1