Youtube Analytics API Demographic dimension "gender" shows on analytics dashboard but gives query invalid on API Explorer

StackOverflow https://stackoverflow.com/questions/17997417

Question

I am currently working with the Youtube Analytics API,

So far i have been able to pull all the data that youtube has to offer except the gender/ageGroup dimensions the query fails everytime,

The docs point to examples to playbacklocation and not the demographic it's self.

I am using the PHP Client Library,

== PHP ==

$analytics_gender = new Google_YouTubeAnalyticsService($client);

$optparam = array('dimensions' => 'gender');

$metrics= "views";

$analytics_demo_gender = $analytics_gender->reports->query("channel==".$channelId, "2012-08-14", "2013-05-30", $metrics, $optparam);

When i run this query i get an error (400) The query is not supported. even though it works just fine for all the other metrics and dimensions.

Was it helpful?

Solution

The gender dimension can only be used with the metric viewerPercentage (and optionally with a country and/or video filter and with an additional ageGroup dimension, if you'd like). You can search the relevant documentation for "gender" to see the exact specifications.

Here's an example of a working report in the API Explorer. Authenticate, and replace CHANNEL_ID with the id of your channel.

OTHER TIPS

It's simple to do this, please check below code snippet to find demographic and gender statics:

request.get({
    url:'https://www.googleapis.com/youtube/analytics/v1/reports?key={Google Api Key}&ids=channel=={channelId}&dimensions=country&metrics=views&end-date={endDate}&start-date={startDate}',
    json:true,
    timeout: 10000,
    headers:{'Authorization':'Bearer '+accessToken}},
    function (err,r,result) {
        console.log(result)
});

If you need to find gender info below code snippet can be used:

request.get({
    url:'https://www.googleapis.com/youtube/analytics/v1/reports?key={Google Api Key}&ids=channel=={channelId}&dimensions=gender&metrics=viewerPercentage&end-date={endDate}&start-date={startDate}',
    json:true,
    timeout: 10000,
    headers:{'Authorization':'Bearer '+accessToken}},
    function (err,r,result) {
        console.log(result)
});

If you need to find gender info along with ageGroup below code snippet can be used

request.get({
    url:'https://www.googleapis.com/youtube/analytics/v1/reports?key={Google Api Key}&ids=channel=={channelId}&dimensions=gender,ageGroup&metrics=viewerPercentage&end-date={endDate}&start-date={startDate}',
    json:true,
    timeout: 10000,
    headers:{'Authorization':'Bearer '+accessToken}},
    function (err,r,result) {
        console.log(result)
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top