【问题标题】:Youtube Analytics API Demographic dimension "gender" shows on analytics dashboard but gives query invalid on API ExplorerYoutube Analytics API 人口统计维度“性别”显示在分析仪表板上,但在 API Explorer 上查询无效
【发布时间】:2013-08-02 13:47:15
【问题描述】:

我目前正在使用 Youtube Analytics API,

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

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

我正在使用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);

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

【问题讨论】:

    标签: php youtube youtube-api google-api-php-client youtube-analytics


    【解决方案1】:

    这很简单,请检查下面的代码 sn-p 以查找人口统计和性别统计数据:

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

    如果需要查找性别信息,可以使用下面的代码sn-p:

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

    如果您需要查找性别信息以及ageGroup,可以使用下面的代码sn-p

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

    【讨论】:

    • 欢迎来到 StackOverflow。请使用缩进而不是 <pre> 块:后者不提供语法突出显示,就像我在建议的编辑中所做的那样。最好的问候。
    【解决方案2】:

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

    Here's an example API Explorer 中的工作报告。进行身份验证,并将CHANNEL_ID 替换为您的频道ID。

    【讨论】:

    • 为支持干杯:D
    • 即使没有错误,我也没有得到任何响应数据。请问您有什么想法吗??
    猜你喜欢
    • 1970-01-01
    • 2018-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-11
    • 2019-03-23
    • 1970-01-01
    相关资源
    最近更新 更多