0
votes

I manage a YouTube CMS and am trying to count the number of uploads within a given month. A CMS can have multiple channels, I want the aggregate number of uploads.

From the documentation, I feel like this should work:

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

But the result is listing all public videos within the timeframe, not just those videos from the channels that I manage within $CMSID.

For reference, the API documentation says:

The forContentOwner parameter restricts the search to only retrieve videos owned by the content owner identified by the onBehalfOfContentOwner parameter. If forContentOwner is set to true, the request must also meet these requirements: The onBehalfOfContentOwner parameter is required. The user authorizing the request must be using an account linked to the specified content owner. The type parameter value must be set to video. None of the following other parameters can be set: videoDefinition, videoDimension, videoDuration, videoLicense, videoEmbeddable, videoSyndicated, videoType.

1

1 Answers

0
votes

If you refer to the documentation, you will see that you have missing part where you can use the forMine parameter. As what was discussed in this SO post.

forMine boolean

This parameter can only be used in a properly authorized request. The forMine parameter restricts the search to only retrieve videos owned by the authenticated user. If you set this parameter to true, then the type parameter's value must also be set to video. In addition, none of the following other parameters can be set in the same request: videoDefinition, videoDimension, videoDuration, videoLicense, videoEmbeddable, videoSyndicated, videoType.

When you check another SO post, it was also cited here that,

The problem is the conflicting search restrictions that you used. To make your search work, leave the forMine parameter empty so it doesn't conflict with your date filters and possibly the q parameter as well.