获取我订阅的所有Youtube频道的列表



我正试图获得我订阅的所有800多个youtube频道的列表。如果有人能提供一个python示例,那就太好了。

还没有尝试示例程序。但是我看了看youtube的api。

您正在寻找YouTube Data API v3订阅:列表端点。由于它需要获得授权凭证,请参阅本指南。如果你想继续使用OAuth 2,下面是API本身建议的Python代码:

# -*- 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()

否则,如果您只想继续使用API密钥,则可以使用以下Python代码执行此操作,该代码需要您正在检索订阅的通道id:

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)

相关内容

  • 没有找到相关文章