google-apigoogle-oauthyoutube-analytics-api

How to make an HTTP call to YouTube Analytics API?


I want to get information about top keywords driving traffic to my own YouTube channel over the past 7 days. In order to do that, I followed all of the instructions. Then I generated a new access_token for my account

When I make such a request:

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'

I receive back an error:

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

What I do wrong when construct this kind of request?


Solution

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

    Is basically a really bad error message telling that you are missing a required field.

    If you check the Documentation you will notice that startdate and enddate are required fields. You have forgotten to add them to your request

    Also when you get that far you separate dimensions and metrics with a , not a ;