Youtube Analytics API The demographic dimension "gender" is displayed on the analytics toolbar, but the request is incorrect in the Explorer API

I am currently working with the Youtube Analytics API,

So far, I managed to pull out all the data that youtube can offer, except for the gender / ageGroup sizes. The request is aborted every time

docs indicate examples to reproduce, not demographic ones.

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 error (400) The query is not supported. although it is great for all other indicators and measurements.

+4
source share
2 answers

The gender dimension can only be used with the viewerPercentage metric (and, if desired, with a country filter and / or video and with an additional ageGroup size, if you want). You can find the appropriate documentation for "gender" to see the exact specifications.

Here is an example of a working report in the API. Authenticate and replace CHANNEL_ID with your channel ID.

+5
source

It’s easier to do this, please check the code snippet below to find demographic and gender statistics:

 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 sex information below the code, you can use the code snippet:

 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 information along with ageGroup below the code snippet, you can use

 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) }); 
0
source

Source: https://habr.com/ru/post/1494767/


All Articles