1

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?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Alex Fruzenshtein
  • 2,846
  • 6
  • 32
  • 53

2 Answers2

2
   "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 ;

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • You was right about the required query params `endDate` and `startDate`. Also it was necessary to change `;` on `,`. In addition to this I found several other problems – Alex Fruzenshtein Jul 10 '19 at 19:10
  • yes, really bad error message.... trying to figure out how to make a channelsections.update, and seeing this same message. The documentation is also very unclear on what is required/missing – monkut Jun 18 '23 at 00:11
0

So the problem was in query params, which I set incorrectly. Here is how the URL should be formed in order to get the data from the question:

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
Alex Fruzenshtein
  • 2,846
  • 6
  • 32
  • 53