Youtube API: Unable to add video to playlist - youtube-api

I'm trying to add a video to my playlist and got the following response.
{
"code" : 400,
"errors" : [ {
"domain" : "youtube.playlistItem",
"message" : "Playlist should use manual sorting to support position.",
"reason" : "manualSortRequired"
} ],
"message" : "Playlist should use manual sorting to support position."
}
I went through the youtube API documentation to understand this error.
https://developers.google.com/youtube/v3/docs/errors#playlistItems_youtube.playlistItems.insert
Here, the description of this error is as following
The request attempts to set the playlist item's position, but the playlist does not use manual sorting. (For example, playlist items might be sorted by date or popularity.) You can address the error by removing the snippet.position element from the resource that the request is inserting. If you want the playlist item to have a particular position in the list, you need to first update the playlist's Ordering option to Manual in the playlist's settings. This settings can be adjusted in the YouTube Video Manager.
I am unable to see Ordering option under playlist settings after navigating to YouTube Video Manager. Any way to resolve this error other than removing snippet.position.

Related

Using the youtube analytics api or youtube data api, is there a way to get the video from a channel with the most comments?

I've been trying for some days now by reading the docs to figure out how to use any of the two APIs mentioned in the title to retrieve a channel's most commented video.
This query doesn't work:
curl --location --request GET 'https://youtubeanalytics.googleapis.com/v2/reports?ids=channel==MINE&dimensions=video&metrics=comments&maxResults=1&sort=-comments&startDate=2022-07-12&endDate=2022-09-12'
But querying for the same dimension but for the views metric instead works:
curl --location --request GET 'https://youtubeanalytics.googleapis.com/v2/reports?ids=channel==MINE&dimensions=video&metrics=views&maxResults=1&sort=-views&startDate=2022-07-12&endDate=2022-09-12'
One weird thing is that even though the documentation specifies that ascending order sorting is working by default (Docs: A comma-separated list of dimensions or metrics that determine the sort order for YouTube Analytics data. By default the sort order is ascending. The - prefix causes descending sort order. ) you can't run some requests without specifically using descending order. For example the views request above.
But changing the sort parameter to sort=view (Ascending) results in the following response:
{
"error": {
"code": 400,
"message": "The query is not supported. Check the documentation at https://developers.google.com/youtube/analytics/v2/available_reports for a list of supported queries.",
"errors": [
{
"message": "The query is not supported. Check the documentation at https://developers.google.com/youtube/analytics/v2/available_reports for a list of supported queries.",
"domain": "global",
"reason": "badRequest"
}
]
}
}
And removing the sort parameter has the same result.
Anyone knows how to solve this mystery with the youtube analytics api?
By using YouTube Data API v3 endpoints you can get the most commented video on a given channel.
Indeed by:
fetching all video ids from the channel by using PlaylistItems: list with part=snippet and playlistId=UPLOADS_PLAYLIST_ID where UPLOADS_PLAYLIST_ID is the channel id with its second character (C) replaced by U.
pass all these video ids to Videos: list with part=statistics
sort on your side all the video commentCounts

How to identify the YouTube videos that can't embed on file

I have a mobile application that embeds some youtube videos in a webview.
The problem is that, using YouTube Data API v3 I get a list of "Embeddable" items to show. But some of them say that "Video unavailable". When I paste the same code on on jsfiddle or a domain or some sort of webserver, it does work but when reading from File or navigating to html string via webview, it doesn't work.
My question is that how can I understand if the video that I'm trying to embed is actually embeddable from file or not?
I have checked youtube data API v3 outputs for each video and I couldn't find any meaningful information.
Is there some other sort of web api or http endpoint that I can check to see if the video is right?
If not, how can I get data from youtube player programatically to see whether it successfully embedded it or not?
The sample list of the youtube videos that can't be embedded in file are following:
https://www.youtube.com/watch?v=TjI3bzvbCU4
https://www.youtube.com/watch?v=QWveXdj6oZU
https://www.youtube.com/watch?v=KEEnap_h8cs
Note: My problem is to identify the unimbeddable items, because I want to load them from file (in a mobile app). Therefore trying to loading it from a webserver isn't an option for me.
Note 2: These blocks aren't regional, they are domain based.
YouTube Data API v3 provides a not working embed page while it says that it is.
While for other videos like this one (ZqYezph-hgg) it works.
So my idea is just to retrieve https://www.youtube.com/embed/VIDEO_ID and see if the video is unplayable like this for instance:
curl -s https://www.youtube.com/embed/TjI3bzvbCU4 | grep "UNPLAYABLE" | wc -l
Returns 1, so this video is unplayable.
curl -s https://www.youtube.com/embed/ZqYezph-hgg | grep "UNPLAYABLE" | wc -l
Returns 0, so this video is playable.
I found this entry on Google Support that might explain why a video is not available.
Quote:
Actually found the issue here. The videos that were displaying this on
embed had "Copyrighted" music playing in the background. YouTube
apparently does not play videos like this while embedded. We had our
user remove the audio and re-uploaded the video and everything is
working fine now.
Hope this helps somebody.
Probably, YouTube Data API is not updated for match the value set by the uploader/owner of the video AND YouTube guidelines for allow embed the videos.
For this case, I suggest you to post a ticket on Issue Tracker.
If you enter to the source code of the video - like: view-source:https://www.youtube.com/embed/TjI3bzvbCU4, you can find there a property called previewPlayabilityStatus as follows:
"previewPlayabilityStatus": {
"status": "UNPLAYABLE",
"reason": "Video no disponible",
"errorScreen": {
"playerErrorMessageRenderer": {
"reason": {
"runs": [{
"text": "Video no disponible"
}]
},
"proceedButton": {
"buttonRenderer": {
"style": "STYLE_DEFAULT",
"size": "SIZE_DEFAULT",
"isDisabled": false,
"text": {
"simpleText": "Mirar en YouTube"
},
"navigationEndpoint": {
"clickTrackingParams": "CAEQ8FsiEwiT6sGfg6j3AhVG25QJHY96Amgu003d"
This info was available throught this endpoint: https://www.youtube.com/get_video_info?video_id=TjI3bzvbCU4, but, now, an HTTP ERROR 410 is returned.
Unfortunately, this info does not provide any useful data about the reason(s) why the video is not available - despite the fact the response of the YouTube Data API says is is embeddable:
"status": {
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true,
"madeForKids": false
},
You can also use this alternative for embed a YouTube video - I share it here because I find it interesting.
Make sure you have your referer and referer-policy set in the header all requests.

How can I solve Video Rating Disabled?

I'm doing a project using the YouTube Data API's Videos.rate endpoint.
And I got some problems: some particular minor channels (e.g. my client's channel) are sending error messages:
{
"error": {
"code": 403,
"message": "The owner of the video that you are trying to rate has disabled ratings for that video.",
"errors": [
{
"message": "The owner of the video that you are trying to rate has disabled ratings for that video.",
"domain": "youtube.video",
"reason": "videoRatingDisabled",
"location": "id",
"locationType": "parameter"
}
]
}
My boss wants to help them to solve that problem, but I don't know how to solve this at all. There is no problem with other major channels with 1M+ subscriptions.
I did my best to google this problem, yet couldn't find good results until now.
Before rating the video, check if the vide has enabled the rating.
I can't test right now, but, and idea could be:
Use getRating and check the items[].rating value - if the result is none or unspecified, then, you have to handle your logic for make them know that this video can't be rated - due its owner disabled rating their video.
The message you show in your question says that you cannot rate that video because the owner doesn't allow it. YouTube Data API wont bypass such restriction and there's not much that can be done further.
Ask your boss (or the owner of the video) about allow rating their video(s) and then verify if the video can be rated, if so, try again rate the video.

DELETEing a YouTube watchLater playlist item failing - returning 404

i have code that deletes an item from my youtube watchLater playlist. this was working ok up to about two weeks ago - now i'm getting a 404 error from youtube.
here's the sequence of requests and responses (with authentication details stripped, of course):
get playlist items request:
GET https://www.googleapis.com/youtube/v3/playlistItems?fields=items/id&part=snippet&playlistId=WLlue5EIJLscoxMgEkEZfq_A
get playlist items response:
{
"items": [
{
"id": "V0xsdWU1RUlKTHNjb3hNZ0VrRVpmcV9BLjU2QjQ0RjZEMTA1NTdDQzY="
}
]
}
delete request:
DELETE https://www.googleapis.com/youtube/v3/playlistItems?id=V0xsdWU1RUlKTHNjb3hNZ0VrRVpmcV9BLjU2QjQ0RjZEMTA1NTdDQzY=
delete response:
{
"error": {
"errors": [
{
"domain": "youtube.playlistItem",
"reason": "playlistItemNotFound",
"message": "Playlist item not found.",
"locationType": "parameter",
"location": "id"
}
],
"code": 404,
"message": "Playlist item not found."
}
}
when i view the playlist via the youtube web site, i can see that the item hasn't been deleted.
the docs for the api indicate that i'm doing everything correctly. while debugging i noticed that the playlist item id is a base64 encoded string; i get 404 using both the encoded and decoded string.
this issue isn't limited to one particular item; it appears any item i place in my watchLater playlist cannot be deleted. i don't have any issues deleting items from other playlists; only watchLater is having this problem.
anyone have any idea what's going on?
Edit (Oct 2016): Google have said the Watch Later playlist has been deprecated. See https://developers.google.com/youtube/v3/revision_history
The issue is closed in the google issue tracker:
Marking this issue as Obsolete as the Watch Later playlist has been deprecated. Please see the Revision History for details: https://developers.google.com/youtube/v3/revision_history
In addition, requests to retrieve playlist details (playlists.list) or playlist items (playlistItems.list) for a channel's watch history or watch later playlist now return empty lists. This behavior is true for the new values, HL and WL, as well as for any watch history or watch later playlist IDs that your API Client may have already stored.

Youtube API v3 Duration PlaylistItem

If I get all Playlist Items with the Youtube Data API v3, I am getting this format for all videos:
"contentDetails": {
"videoId": "KUL_AHeC4zw",
"startAt": "PT0S",
"endAt": "PT21M12.667S"
}
Whats that thingie next to endAt? Why is there a point in the middle? I expect some kind of PT21M54S. I just want the duration as I would get it when I am fetching a single video. Is that a bug or am I just not able to understand that ISO Date Format?
This field "endAt" is not the same as the "duration" of the video, but where the playlist owner wants it to stop playing. The video duration is located in the video resource and not in the playlistItem. And it requieres another lookup request.
You can find the definitions of the fields in the YouTube documentation. See for those resource definitions:
https://developers.google.com/youtube/v3/docs/playlistItems#resource
and https://developers.google.com/youtube/v3/docs/videos#resource
"startAt": "PT0S",
"endAt": "PT21M12.667S"
This property has been deprecated and, if set, its value is ignored.
For More Info Check at https://developers.google.com/youtube/v3/docs/playlistItems#resource

Resources