4

我目前正在使用 Youtube Analytics API,

到目前为止,我已经能够提取 youtube 必须提供的所有数据,除了查询每次都失败的性别/年龄组维度,

文档指向播放位置的示例,而不是其自身的人口统计。

我正在使用PHP 客户端库

== 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);

当我运行这个查询时,我得到一个error (400) The query is not supported.即使它适用于所有其他指标和维度。

4

2 回答 2

5

gender维度只能与指标一起使用(如果您愿意,还viewerPercentage可以选择与国家和/或视频过滤器以及其他维度一起使用)。ageGroup您可以在相关文档中搜索“性别”以查看确切的规格。

这是 API Explorer 中的工作报告示例。进行身份验证,并替换CHANNEL_ID为您的频道的 ID。

于 2013-08-01T21:14:08.503 回答
1

这样做很简单,请检查下面的代码片段以查找人口统计和性别统计数据:

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

如果您需要在下面的代码片段中查找性别信息,可以使用:

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

如果您需要查找性别信息以及年龄组,可以使用下面的代码片段

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)
});
于 2016-07-26T09:12:31.130 回答