How can I exclude shorts from YouTube API Data v3 - youtube

I currently use something like https://www.googleapis.com/youtube/v3/search?part=id&order=date&channelId=CHANNELID&maxResults=1&type=video&key=KEY and I want to be able to retrieve only the latest video and to totally exclude shorts.
How can I achieve this? 🤔

The Youtube search method
Will allow you to search for things like keyword, location, events, your own videos and related videos.
There is no way to filter or limit videos returned. Your only hope would be to sort them out locally when you get the results.
You may want to add a feature request here there is this one but it's really old Search API: More flexible/logical videoDuration requests

(sorry its my 1st time answering at stackoverflow, so might not be descriptive)
if you you use youtube serch method
then you'll realise that shorts description are assigned as empty string "" where as the videos have some description . so with an if condition like below can slove your problem (js)
if(!(video.snippet.description == ""))

Related

How to get result from youtube api search morethan 5?

I tried to get youtube search from this link
https://www.googleapis.com/youtube/v3/search?part=snippet&key={my_api_key}&q=plane
it's work good. But i want to know how can i get result morethan 5 ?
ref : https://developers.google.com/youtube/v3/docs/search/list
Just in case anyone needs a solution for this.
You just need to add &maxResults=50 (to get a maximum of 50 results of course) at the end of the link / API call.
The person who asked the question was using &max-results... and not &maxResults... which is why it did not work.
The only thing you need to set here is maxResults. Now, if you're still getting 5, the problem maybe that there's really no other videos to list or your search filter is wrong.
The nextPageToken solution do not apply if you have maxResult set to 50 but are only getting 5. The problem could be your filter or the number of videos available.

Programmatically search Youtube videos and return the first available one on a web page

Good day!
Let's say I have a web page dedicated to a specific song by a specific author (eg "Imagine" by "John Lennon"). I would like to programmatically:
Search Youtube for the first n videos with "Imagine John Lennon"
Loop through these results to find a video which is available in the country where the user is located
Display the first video that matches the constraints on point 2. If no video matches them, then I won't display any video.
How can I do this? Is it better to do it with PHP or Ajax calls? I already checked some similar questions (1, 2) but as they are "old" I was wondering if there is a better method now.
Thanks for any help
This can be done with a single call to the Search: list endpoint, setting the 'q' and 'regionCode' parameters. Use any programming language you prefer.

Can't get endAt on videos when calling

I'm using GET https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails%2Csnippet&maxResults=50&playlistId=PLFs4vir_WsTwwb2zqmtE2WTEFdc7AQHnc&key={YOUR_API_KEY}
This returns all data, but only videoId in each video contentDetails. Maybe I'm missing something here?
YouTube has removed the features that set start and end times to playlist items: here's a product forum post that details this (and indicates an official response from Google account reps):
https://productforums.google.com/forum/#!topic/youtube/Gipu_cCDScI
Since playlists can no longer set start/end times on its items, the API no longer delivers them.
Not an answer, but a workaround. You can retrieve a playlist and use videos list with up to 50 videoIds in the URL to retrieve each video duration.

Google youtube API, how do i search for specific keyword?

I want to search for keyword related youtube videos, I'm using youtube getdata API.
Reading documentation I came up with this:
http://gdata.youtube.com/feeds/api/videos/-/". urlencode($kwd) ."?orderby=viewCount&max-results=". $max ."&alt=json
But this is not a real search, it gives urls taged with keyword... Youtubes internal search works quite differently I imagine, because comparing results don't match at all.
Any ideas?
The URL you offer does a search for any videos in a category where the category includes your keyword. What you want to do instead is to send a query string:
"https://gdata.youtube.com/feeds/api/videos?q=". urlencode($kwd) ."&orderby=viewCount&max-results=". $max ."&alt=json"
This way the feed will match right on the videos rather than the categories.
In the newer v3 of the API, your call would look like:
"https://www.googleapis.com/youtube/v3/search?part=snippet&q=".urlencode($kwd)."&maxResults=".$max."&order=viewCount&key={YOUR_API_KEY}"
Use Data API v3, search->list method.
GET https://www.googleapis.com/youtube/v3/search?part=snippet&q=term&key={YOUR_API_KEY}
In my opinion, I would use the "q" parameter, for example to search for "dog"
var request = gapi.client.youtube.search.list({
part: 'snippet',
q: "dog"
});
But I'm just a noob the others guys answers are probably better.

YouTube API "published" filter doesn't seem to work

I'm trying to use the YouTube API to return videos that were recently published, but the filter I'm using doesn't seem to work as expected.
This API call only returns two videos whereas there should be tons more that were published after March 1st:
https://gdata.youtube.com/feeds/api/videos?q=&fields=entry[xs:dateTime(published)%20%3E%20xs:dateTime('2013-03-01T12:00:00.000Z')]
However, if I add a query string, then many more results are returned. For example:
https://gdata.youtube.com/feeds/api/videos?q=surfing&fields=entry[xs:dateTime(published)%20%3E%20xs:dateTime('2013-03-01T12:00:00.000Z')]
Anyone know why? Is there another approach I should be using to just get me the latest videos published regardless of query string?
I understand your confusion, but that's not what the fields= parameter is used for. The documentation should hopefully clear things up, but to summarize, using fields= in that manner is equivalent to making a request without the fields= parameter and then filtering the results of that request so that it only includes the entries that match your filter.
So if your request without fields= would normally return 25 specific videos, adding fields= to it will give you a response that includes somewhere between 0 and 25 videos—all the non-matching videos are filtered out.
You can request a feed of recently published videos without any other filters using http://gdata.youtube.com/feeds/api/videos?v=2&orderby=published

Resources