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.
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.
Related
So, I have a request that should list my subscribers who do not have the private subscriptions option enable. My request is:
response = youtube.subscriptions().list(
part="snippet",
maxResults=50,
mySubscribers=True
).execute()
However, in items resource, every channel returned is my own channel. My channel name, ID and profile images. Is this the problem with the API or am I making a wrong request?
I also tried using the Try this API option on the documentation, but it also returns the same result.
https://developers.google.com/youtube/v3/docs/subscriptions/list
Thank you for any help you can give
According to the official docs you already quoted, you should have passed to your API call the parameter part as:
part="snippet,subscriberSnippet".
The subscriberSnippet part gives you the needed info:
subscriberSnippet (object)
The subscriberSnippet object contains basic details about the subscriber.
For what concerns the snippet part, the official doc is indeed a bit ambiguous:
snippet (object)
The snippet object contains basic details about the subscription, including its title and the channel that the user subscribed to.
Nevertheless, the info you get from part="snippet" only is correct.
As mentioned in the doc, search list api returns a collection of search results that match the query parameters specified in the API request. By default, a search result set identifies matching video, channel, and playlist resources, is this searching done on title, description and tag fields or only on title or tag field of the video, channel and playlist resource?
you can simply use allintitle operator to search youtube videos on title
so your query will look like
allintitle:"How to dance"
You can read more about this here and here
You can do the same using youtube API
According to the Document :
Required parameters:
part
string
The part parameter specifies a comma-separated list of one or more
search resource properties that the API response will include. Set the
parameter value to snippet.
You can try it in YouTube Search List API Try It. Remember to be authorized first before you execute it.
The other parameters like you mentioned earlier: title can be replaced with the q parameter to be specific with your search. The q parameter can be found in the Search For Files document.
You can search or filter files with the files.list method of the Drive
API. These methods accept the q parameter which is a search query
combining one or more search clauses. Each search clause is made up of
three parts.
Unfortunately, you cannot select where the q will look into e.g. title, tag, description.
Hope this helps.
I'm querying YouTube channels to retrieve playlist metadata like this:
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=5&playlistId={PLAYLIST_ID}&key={API_KEY}
This query returns an array of all of the videos on the channel. Each object in that array includes various fields that provide metadata on each video, but none of these fields include the tags associated with the video. I can get that data using a query like this:
https://www.googleapis.com/youtube/v3/videos?key={API_KEY}&fields=items(snippet(title,description,tags))&part=snippet&id={VIDEO_ID}
The problem with that is that now I need to issue a separate query for every single video that comes back in the first query.
So, my question is, is there a way that I can get these tags included as part of the initial JSON object from the first query? Can I add any parameters that will request this data be included with that response?
Thanks for any help!
Short answer: No.
The PlaylistItems: list documentation does not show a way to get video tags from the playlistItems endpoint. The only parts available are id, snippet, status and contentDetails and neither of those contain tags.
However!
You do not have to make a request for each video in the playlist! The documentation states:
The id parameter specifies a comma-separated list of the YouTube video ID(s) for the resource(s) that are being retrieved. In a video resource, the id property specifies the video's ID. (string)
That means you can supply multiple, comma-separated video ids to the videos endpoint.
Example:
GET https://www.googleapis.com/youtube/v3/videos?part=snippet&id=kOkQ4T5WO9E,a59gmGkq_pw,Io0fBr1XBUA&key={YOUR_API_KEY}
So in total, it will cost you two requests to get the tags of all videos in a playlist.*
*In practice, you might have to make more than two requests. If I remember correctly, YouTube limits the returned items to 50 per request. Thus, if the playlist contains more than 50 videos, you will have to make another request with the pageToken parameter set.
I try to retrieve an HLS stream URL of my videos on Dailymotion, calling /video/ API with stream_hls_url value in the fields parameter. But I get a 403 error with the following message:
Unsufficient roles for the 'fields' parameter of 'GET /video/<id>' with 'stream_hls_url' value, roles required: content-partner, can-read-video-streams
How could I obtain these roles, given that I'm a Dailymotion partner?
You should either contact your Dailymotion content manager if you have one, or get in touch with us by writing your request to https://faq.dailymotion.com/hc/en/requests/new
Anyone coming to this question with a similar response from an API request; please check the fields you're requesting within your request against those listed in the Dailymotion API Data API Reference.
Often this "403" response, seemingly due to "Unsufficient Roles" (yes that's a typo), is actually down to requesting a field that no longer exists within the defined reference (linked above). This happens more than it should, with little or no notice to the end user - as demonstrated here.
I hope this helps :)
I am authenticating with google to try and get youtube analytics my problem is that i don't know how to filled you the parameters when quering youtube
here i am making a new service: and then try to query it
I am not sure what to put in the "ids" parameter or where to find it?
What do I put there?
_analyticService = new YoutubeAnalyticsService(_authenticator = CreateAuthenticator());
...
_analyticService.Reports.Query("ids", "2013-01-01", "2013-02-02", "views").Fetch();
The ids parameter is the an expression with the id of your channel. If you go to http://www.youtube.com/analytics and click on the title with your own channel name, you get a link like http://www.youtube.com/channel/UCYHMS8hN8s49F93iJuEgG6w The last part is the id of your channel. You have to use this as the ids parameter in an expression like "channel==UCYHMS8hN8s49F93iJuEgG6w". This is to query in the context of your own channel. This is needed as you might have access to several channels.
I can query views for one of my videos by: https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DUCYHMS8hN8s49F93iJuEgG6w&start-date=2013-01-01&end-date=2013-02-02&metrics=views&dimensions=day&filters=video%3D%3D_iwmv6644dA&sort=day&key={YOUR_API_KEY}
Try to use the API explorer at the bottom of this page, there are some text explaining the different parameters there as well. https://developers.google.com/youtube/analytics/v1/
Hope it goes well!