I am noticing a difference between the number of comments shown in YouTube for a specified Video and the number of comments that actually appear after the comments are loaded.
Example: https://www.youtube.com/watch?v=aD1VmjGOb_g
This Video shows 21 comments just below the Video description, but if you count the comments it only has 13! The total shown won't get to 21 even if you sum the amount of replies!
You'll see all 21 comments if you choose the "Newest first" sorting option:
When using YouTube data API you should use order: 'time' when calling the commentThreads
Related
I am trying to get videos of a particular channel (like :- Luis Fonsi) in highest views order. And I am passing order parameter to sort the response by viewCount
like :-
order=viewCount
URL :-
https://www.googleapis.com/youtube/v3/search?key=[MY-API-KEY]&channelId=UCxoq-PAQeAdk_zyg8YS0JqA&part=snippet,id&order=viewCount&maxResults=20000
When I try to run it then It is not sorting as I expected. I was expecting first song would be Despacito But It got another one which definitely don't have the highest views.
As mentioned in Youtube-API Documentation in search section.
viewCount – Resources are sorted from highest to lowest number of views.
It is not working like this.
I have tried many times but it is still not working.
Any help would be much Appreciated.
YouTube Data API v3 is broken on some aspects, if I were you, I would just retrieve all videos from the given YouTube channel and then sort them.
To do so:
Get the channel's uploads playlist id by using Channels: list with part=contentDetails.
Get the channel's videos by using PlaylistItems:
list
with playlistId=UPLOADS_PLAYLIST_ID (replacing
UPLOADS_PLAYLIST_ID with the one you just obtained).
Get each
video's view count by using part=statistics with Videos:
list.
I want to get all video comments of a channel. At the moment I'm proceeding like this:
1.) Getting all video ids of a channel (1 quota)
2.) Sending new request with "part: statistics" and getting the total comment count to a youtube video (2 Quota)
It's polling in 30 seconds intervall and I wanted to reduce the quota. Therefore is there a possibility to query whether there are any new comments for a channel videos (Total amount of comments for a channel including channel comments would be fine too)? Like saving the old value of total amount of comments and comparing it with the new amount of the query?
No, from my experience.
I would not use video's commentCount.
- you can pull over 260 comments from a video whose comment count is only 243. https://www.youtube.com/watch?v=87xYGDR_eME
I would not try optimizing by stopping at recent comments.
- this would work for threads, but each thread has replies. So you have to check each thread anyways just to see if they have new replies.
- note: it's dangerous to use commentThreads' reply mode, as it may only return a subset of replies. Instead get a comment list using parentId.
Perhaps, if you sort by time and save the id of comments you've collected, you can use cheap requests like id to figure out which comments are new and pull them with snippet.
- stop when you get to an id you've already gathered.
This may not be simple though because publishedAt or updatedAt leave two questions:
will an old comment be bumped to the top if it's edited? If so, you can't stop once you recognize a comment id, because it might have jumped ahead of new comments (unless the change the id when it's edited).
will the old comment not be bumped if edited? If this is the case, you need to check snippet for each comment as the textDisplay may be different. In this case I can see no optimizations.
For getting video comments I use this example:
https://www.googleapis.com/youtube/v3/commentThreads?part=snippet,replies&' .
'videoId=' . $video->id . '&maxResults=100&' .
'key=' . $ytApp->apiKey;
My question is: are there other filters except maxResults so I can get only the last comments of a video filter it by a date, or another filter that I can get only last comments not all comments or 100 comments per page?
order string
The order parameter specifies the order in which the API response should list comment threads. Valid values are:
time - Comment threads are ordered by time. This is the default behavior.
relevance - Comment threads are ordered by relevance.
I have been using the YouTube Data API v3 to make search requests to get basic details of all of the videos on a particular channel. The channel I am searching contains a few hundred videos so I make search requests in batches of 50 using the nextPageToken, an example of which is shown below:-
https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=50&channelId=<channelid>&key=<key>&pageToken=<nextPageToken>
This appears to work fine until the penultimate and final searches, where I begin to see varying results. Some of the videos in the results don't have an Id associated with them, which seems a little strange? However, more interesting is the fact that the number of videos which are missing an id varies if you make the same request repeatedly.
An example of the sorts of results I am getting (based upon 100 same searches):-
Penultimate page (100 requests): 60 results of 41 videos with an id and 9 without an id, 38 results of 37 videos with an id and 13 without an id and 2 results of 38 videos with an id and 12 without an id.
Final page (100 requests): 64 results of 25 videos all with an id and 36 results of 24 videos with an id and 1 without an id.
Clearly this will lead to an inconsistent total number of videos returned as I require there to be an Id (which is how I noticed this was occurring in the first place).
I am testing these results in a unit test currently to keep things isolated.
Is there something I'm missing here or is there just a bug in the API?
UPDATE
Added the parameter "type=video" as suggested in the comments. This seems to limit the issue to the last page of the search as noted, but the issue still persists.
Is there some way I can retrieve more than 100 results using YouTube API?
I can retrive upto 100 results using this query string:
https://gdata.youtube.com/feeds/api/videos?q=football&orderby=relevance&start-index=1&max-results=10&v=2
But when I try
https://gdata.youtube.com/feeds/api/videos?q=football&orderby=relevance&start-index=101&max-results=10&v=2
I get:
http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/"C0YFQHg9fyp7I2A9WhBVGUk."'>tag:youtube.com,2008:videos2013-04-26T01:51:51.667Zhttp://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>Videos matching: footballhttp://www.youtube.com/img/pic_youtubelogo_123x63.gifhttps://www.youtube.com'/>http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos?v=2'/>http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos/batch?v=2'/>https://gdata.youtube.com/feeds/api/videos?q=football&start-index=101&max-results=10&orderby=relevance&v=2'/>https://gdata.youtube.com/feeds/api/videos?alt=atom-service&v=2'/>https://gdata.youtube.com/feeds/api/videos?q=football&start-index=91&max-results=10&orderby=relevance&v=2'/>YouTubehttp://www.youtube.com/http://gdata.youtube.com'>YouTube data API10010110
From what I understand, you can get 999 results using YouTube search API. Why is this limited to 100 here? Is there a workaround for me to get more than 100 results?
Thanks!
I can't speak to whether or not something has changed internally that is now capping totalResults at 100, but it seems to be a pretty common problem across the board today. However, if you were to try using v3 of the API, this wouldn't be an issue: for example, this query:
https://www.googleapis.com/youtube/v3/search?q=football&part=id&key=YOUR_DEVELOPER_KEY
Will give you many, many more total results. With v3, you can set the maxResults parameter up to 50 videos returned for each response, and then paginate through the responses by setting the pageToken parameter to whatever the "nextPageToken" attribute of a given response is.
Try like this https://gdata.youtube.com/feeds/api/videos?q=football&orderby=relevance&v=2
It will take the default size. When you use the start index and size you are using the pagination mechanism. I guess thats the problem here. And misfortune is that Google youtube API supports only max of 50 videos per query. Its there in the docs. 999 videos are the total videos that can be in a video feed. Not the number of videos it would query out. Dont mistakenly take it as it would return you all the videos. You have to use pagination with start index and size inorder to go through all the videos.
you can use this url
https://www.googleapis.com/youtube/v3/search?q=football&part=id&key=YOUR_DEVELOPER_KEY&max-results=150
and you easily get more than 100 results
I'm confused by this same issue - video search queries with start-index > 100 do not return any results:
http://gdata.youtube.com/feeds/api/videos?v=2&q=skateboarding+dog&max-results=50&start-index=101
and queries with a start-index < 100 return only the number of videos up to 100:
http://gdata.youtube.com/feeds/api/videos?v=2&q=skateboarding+dog&max-results=50&start-index=90
gives you 10 videos.
Shouldn't you be able to access results beyond the first 100 returned by the search?
There's a caching/escalating issue for pagination.
Check this answer here.
The correct way to page through a feed is to make the first request
for the feed without a start-index, and then check to see whether
there's a <link rel="next'...> and if so, use that URL to retrieve the
next page of a feed.
I discovered that if you put a small pause between each pagination call to API, it returns 400 results, it's mean 1 call per page putting 2 second between each call. It works for my. If you wuould like get more it, you have to close the connection to API and try again one or two minutes later.