【问题标题】:YouTube API - Count uploads within a time periodYouTube API - 计算一段时间内的上传次数
【发布时间】:2018-07-02 19:46:33
【问题描述】:

我管理一个 YouTube CMS 并尝试计算给定月份内的上传次数。一个 CMS 可以有多个频道,我想要上传的总数。

从文档中,我觉得这应该可行:

function videosList($service, $part, $params) {
    $params = array_filter($params);
    $response = $service->search->listSearch($part,$params);
    print_r($response);
}

videosList($youtube,"snippet",array(
    array('forContentOwner' => true),
    'type' => 'video',
    'maxResults' => 1,
    'onBehalfOfContentOwner' => $CMSID,
    'publishedBefore' => date("c",strtotime("first day of this month")),
    'publishedAfter' => date("c",strtotime("first day of last month"))            
));

但结果是列出了时间范围内的所有公开视频,而不仅仅是我在 $CMSID 内管理的频道中的视频。

作为参考,API 文档说:

forContentOwner 参数将搜索限制为仅检索由 onBehalfOfContentOwner 参数标识的内容所有者拥有的视频。如果 forContentOwner 设置为 true,则请求还必须满足以下要求: onBehalfOfContentOwner 参数是必需的。 授权请求的用户必须使用与指定内容所有者关联的帐户。 type 参数值必须设置为 video。 以下其他参数均不可设置:videoDefinition、videoDimension、videoDuration、videoLicense、videoEmbeddable、videoSyndicated、videoType。

【问题讨论】:

    标签: youtube youtube-api youtube-data-api youtube-analytics-api


    【解决方案1】:

    如果您参考documentation,您会发现您缺少可以使用forMine 参数的部分。正如SO post 中所讨论的那样。

    forMine 布尔值

    此参数只能在正确的authorized request 中使用。 forMine 参数将搜索限制为仅检索视频 由经过身份验证的用户拥有。如果将此参数设置为 true, 那么 type 参数的值也必须设置为 video。在 此外,以下其他参数均不可设置 相同的请求:videoDefinitionvideoDimensionvideoDurationvideoLicensevideoEmbeddablevideoSyndicatedvideoType

    当你查看another SO post时,这里也提到了,

    问题在于您使用的搜索限制相互冲突。到 使您的搜索工作,将forMine 参数留空,以便 与您的日期过滤器和可能的 q 参数不冲突 也是。

    【讨论】:

    • 经过身份验证的用户是拥有多个 CMS 的 YouTube 合作伙伴。所以我需要同时指定 forContentOwner 和 onBehalfOfContentOwner 参数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-27
    • 2018-04-11
    • 2015-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多