Problem connecting to Twitter. Please try again.
Problem connecting to Twitter. Please try again.
Problem connecting to Twitter. Please try again.
Problem connecting to Twitter. Please try again.
Problem connecting to Twitter. Please try again.

Return to Video

YouTube APIs: Search Explained

  • 0:00 - 0:09
    Hi, I'm Jeff Fisher, and in this video, we're going to talk about how to search for videos using the YouTube API
  • 0:09 - 0:13
    A common operation on YouTube is searching for videos
  • 0:13 - 0:16
    You search for videos in the API by using the videos feed.
  • 0:16 - 0:20
    We specify our search term with the 'q' parameter. You can specify
  • 0:20 - 0:25
    You can specify a more complicated search term by URL escaping it.
  • 0:25 - 0:28
    There are many versions of the API
  • 0:28 - 0:34
    which we can specify which version we want to use using the 'v' parameter, or a special header.
  • 0:34 - 0:39
    Since there are many cute puppy videos on YouTube, and we don't want to handle them all at once,
  • 0:39 - 0:45
    we can specify how many we want by using 'max-results.'
  • 0:45 - 0:49
    Since we only want 10 at once, but we might want to page to the next 10,
  • 0:49 - 0:54
    we can look at the feed that's returned to the API for a 'link' element with 'rel' equals 'next'
  • 0:54 - 0:58
    This will identify the next page of results, and is the proper way of paging through a feed.
  • 0:58 - 1:04
    If you look at that 'next' link, you'll notice it has a 'start-index' parameter, which identifies the beginning of the next page
  • 1:04 - 1:11
    However, you should not try to set this parameter manually and instead always extract the value of the 'next' link from the feed
  • 1:11 - 1:16
    Now let's talk about some other query parameters that you can use with the YouTube API
  • 1:16 - 1:22
    First, we're going to talk about 'orderby'. By default, results are returned in order of relevance
  • 1:22 - 1:29
    but you can also have them ordered by rating, view count, and the date they were published.
  • 1:29 - 1:34
    You can also search for all the videos uploaded by a particular YouTube user with the 'author' parameter.
  • 1:34 - 1:38
    This is equivalent to retrieving their uploads feed.
  • 1:38 - 1:42
    In version 2 of the API, we added location based search
  • 1:42 - 1:49
    where you can pass latitude and longitude information and find videos that occurred near that point.
  • 1:49 - 1:53
    Since a large number of videos only have descriptive locations, such as London,
  • 1:53 - 1:59
    if you only wish for videos with explicit latitude and longitude information to be returned,
  • 1:59 - 2:03
    add an exclamation point to your query.
  • 2:03 - 2:10
    To only show embeddable videos, such as for embedding on an external webpage, use the 'format' parameter.
  • 2:10 - 2:14
    If you only want results in a specific language, you can use language restrict.
  • 2:14 - 2:22
    Note this is only for video metadata, and not the audio track of the video
  • 2:22 - 2:25
    You can also specify a safeSearch value which defaults to 'moderate',
  • 2:25 - 2:32
    but can also be 'strict' or 'none' for filtering restricted content.
  • 2:32 - 2:34
    Some videos cannot be played in certain locales.
  • 2:34 - 2:39
    You can specify the locale of your user by passing in their country code or their IP address
  • 2:39 - 2:41
    in which case we'll figure out their country code for you.
  • 2:41 - 2:46
    Note this is only to improve the user experience, as it will filter out videos they cannot play.
  • 2:46 - 2:52
    Using this parameter will not affect the videos that they can play.
  • 2:52 - 2:57
    YouTube has a number of video categories, such as Comedy, News and Politics, and more.
  • 2:57 - 3:04
    If we only wanted videos in the Comedy category, we can use the 'category' parameter to retrieve them.
  • 3:04 - 3:09
    If you are familiar with other Google Data APIs, you can also use the below syntax.
  • 3:09 - 3:18
    If you want to do a tag search, you can use the same mechanism, such as searching for all videos that have the tag 'puppy'
  • 3:18 - 3:24
    Note that the video category started with an uppercase letter, whereas tags are all lowercase.
  • 3:24 - 3:28
    This means that the above search is for all videos in the Comedy category,
  • 3:28 - 3:33
    whereas the below search is for videos that have the tag 'comedy'.
  • 3:33 - 3:37
    You can also mix and match to combine the different query parameters we have discussed here.
  • 3:37 - 3:42
    For example, if you want to query for kitten videos in the Comedy category
  • 3:42 - 3:48
    that are embeddable on external webpages, you could use this query.
  • 3:48 - 3:52
    YouTube also provides lists of popular videos
  • 3:52 - 3:55
    These are exposed in the API as standard feeds.
  • 3:55 - 4:02
    Such as the top rated videos, the most viewed videos, and the most discussed videos.
  • 4:02 - 4:06
    We can also look at the top rated videos that were uploaded this week using the 'time' parameter.
  • 4:06 - 4:14
    We could also look at the top rated videos this month, or today.
  • 4:14 - 4:21
    You are also able to look at only the top rated videos in this particular category, such as Comedy.
  • 4:21 - 4:25
    Note that this is different from using the 'category' query parameter we talked about earlier.
  • 4:25 - 4:30
    The above feed is the top 100 rated videos in the Comedy category.
  • 4:30 - 4:39
    Whereas the bottom is -- of the top 100 rated videos on YouTube, which ones are in the Comedy category.
  • 4:39 - 4:48
    You can also look at regional versions of the different standard feeds, such as the top rated Comedy videos in Japan.
  • 4:48 - 4:51
    Hopefully, you're getting pretty excited about using the YouTube API
  • 4:51 - 4:57
    But before you get started, we want to go over a few simple caveats.
  • 4:57 - 5:04
    You cannot retrieve more than 1000 videos in a video search feed. This is the same as YouTube.com.
  • 5:04 - 5:07
    The openSearch totalResults value is an approximation.
  • 5:07 - 5:14
    This is part of why you should not do pagination manually, but instead use the 'next' link.
  • 5:14 - 5:18
    Let's go back to our earlier example about searching for cute puppy videos.
  • 5:18 - 5:23
    Because YouTube is a large video website, the search information may be cached.
  • 5:23 - 5:28
    This means that the most recently uploaded cute puppy videos may not be displayed in the results.
  • 5:28 - 5:32
    It also means that the information in these videos, such as the title and description,
  • 5:32 - 5:36
    may take a couple hours to be updated in the search index.
  • 5:36 - 5:43
    Also, statistics about the video, such as view count and favorite information may not be up to date.
  • 5:43 - 5:50
    For videos uploaded as private, and later made public, it will take even longer to enter into the search index.
  • 5:50 - 5:55
    What if you know the ID of a video you want to retrieve information on.
  • 5:55 - 6:01
    Similar to searching for videos on YouTube, this information will be cached.
  • 6:01 - 6:08
    This is also true if you retrieve it through the uploads feed for a user when you're not authenticated as them.
  • 6:08 - 6:16
    However, if you do authenticate as them, you will retrieve uncached information, which will be fresh.
  • 6:16 - 6:20
    Also, if you retrieve the uploads feed as the user, while authenticating as that user,
  • 6:20 - 6:25
    you will receive information about videos that is not cached.
  • 6:25 - 6:31
    This means it will the most recent information that YouTube has. It will be ordered by the published time.
  • 6:31 - 6:35
    However, if you add a query parameter, such as 'orderby' to this feed,
  • 6:35 - 6:41
    even though you're authenticated, the results will be cached.
  • 6:41 - 6:46
    Two query parameters that will not affect the caching process, are start-index and max-results,
  • 6:46 - 6:50
    so you can still page through a feed.
  • 6:50 - 6:53
    If you are using one of our provided client libraries,
  • 6:53 - 6:57
    there will be objects and methods which will help you build search queries on YouTube.
  • 6:57 - 7:01
    Please check the documentation for these client libraries for specifics.
  • 7:01 - 7:07
    All the information in this video is also available in our documentation on code.google.com.
  • 7:07 -
    Thanks for watching!
Title:
YouTube APIs: Search Explained
Description:

Jeff Fisher does an overview of the different parameters and filters you can use with YouTube search through the API.

All the documentation can be found at:
http://code.google.com/apis/youtube

more » « less
Video Language:
English
Duration:
07:09
Amara Bot added a translation

English subtitles

Revisions