【问题标题】:YouTube Analytics API - Total views grouped by channels for a content ownerYouTube Analytics API - 内容所有者按频道分组的总观看次数
【发布时间】:2021-06-27 10:43:12
【问题描述】:

我正在尝试获取内容所有者拥有的每个频道的总观看次数。

我可以获得所有频道的总观看次数,但我想获得每个频道的观看次数。

以下是我试过的代码。 我设置了dimensions=channel 来执行此操作,但它返回了 400 错误。


from googleapiclient.discovery import build


analytics_service = build("youtubeAnalytics", "v2", credentials=credentials)

report_result = analytics_service.reports().query(
    ids= f'contentOwner=={owner_id}',
    startDate='2020-12-01',
    endDate='2021-03-30',
    dimensions='channel',  # <-- It raise the error.
    metrics='views,comments,likes,dislikes',
    filters='uploaderType==self',
).execute()

错误:

HttpError: <HttpError 400 when requesting https://youtubeanalytics.googleapis.com/v2/reports?ids=contentOwner%3D%3DkNuvRJ6GzXE5GEKbcUp7MA&startDate=2020-12-01&endDate=2021-03-30&dimensions=channel&metrics=views%2Ccomments%2Clikes%2Cdislikes&filters=uploaderType%3D%3Dself&maxResults=10&sort=-views&alt=json returned "The query is not supported. Check the documentation at https://developers.google.com/youtube/analytics/v2/available_reports for a list of supported queries.". Details: "The query is not supported. Check the documentation at https://developers.google.com/youtube/analytics/v2/available_reports for a list of supported queries.">

我查看了API 的文档,但找不到获取它的方法。
请告诉我你是否知道这样做的好方法。

谢谢。

【问题讨论】:

    标签: python google-cloud-platform youtube youtube-api youtube-analytics-api


    【解决方案1】:

    我想不出具体的方法,但你总是可以导出所有的 channelID 和 对每个频道 ID 发出请求并像这样获取它。

    from googleapiclient.discovery import build
    
    
    analytics_service = build("youtubeAnalytics", "v2", credentials=credentials)
    
    report_result = analytics_service.reports().query(
        ids= f'contentOwner=={owner_id}',
        startDate='2020-12-01',
        endDate='2021-03-30',
        dimensions='day',
        metrics='views,comments,likes,dislikes',
        filters='channel=={channelID};uploaderType==self',
    ).execute()
    

    【讨论】:

      猜你喜欢
      • 2013-11-16
      • 2012-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-04
      • 2013-01-04
      • 2022-08-05
      • 1970-01-01
      相关资源
      最近更新 更多