如何通过HTTP调用YouTube Analytics(分析)API?

时间:2019-07-10 15:18:09

标签: google-api google-oauth youtube-analytics-api

我想获取有关在过去7天内吸引流量访问我自己的YouTube频道的热门关键字的信息。为了做到这一点,我遵循了所有的instructions。然后,我为我的帐户生成了一个新的 access_token

当我发出这样的请求时:

curl -X GET \
  'https://youtubeanalytics.googleapis.com/v2/reports?dimensions=insightTrafficSourceDetail;7DayTotals&metrics=views&filters=insightTrafficSourceType==YT_SEARCH;channel==MINE&maxResults=10&sort=-views' \
  -H 'Authorization: Bearer access_token'

我收到一个错误:

    "error": {
        "code": 400,
        "message": "Required",
        "errors": [
            {
                "message": "Required",
                "domain": "global",
                "reason": "required"
            }
        ]
    }
}

构造这种请求时我做错了什么?

2 个答案:

答案 0 :(得分:1)

   "error": {
        "code": 400,
        "message": "Required",
        "errors": [
            {
                "message": "Required",
                "domain": "global",
                "reason": "required"
            }
        ]
    }

基本上是一条非常糟糕的错误消息,告诉您缺少必填字段。

如果选中Documentation,则会发现startdate and enddate是必填字段。您忘记了将它们添加到您的请求中

此外,当您达到此程度时,您可以使用而不是;分隔维度和指标;

答案 1 :(得分:0)

所以问题出在查询参数中,我设置不正确。以下是应如何构造URL以便从问题中获取数据的方法:

https://youtubeanalytics.googleapis.com/v2/reports?dimensions=insightTrafficSourceDetail&metrics=views&filters=insightTrafficSourceType==YT_SEARCH&maxResults=10&sort=-views&startDate=2019-07-03&endDate=2019-07-10&ids=channel==MINE
相关问题