[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.03,0:00:08.62,Default,,0000,0000,0000,,Hi, I'm Jeff Fisher, and in this video, we're going to talk about how to search for videos using the YouTube API Dialogue: 0,0:00:08.62,0:00:12.60,Default,,0000,0000,0000,,A common operation on YouTube is searching for videos Dialogue: 0,0:00:12.60,0:00:15.91,Default,,0000,0000,0000,,You search for videos in the API by using the videos feed. Dialogue: 0,0:00:15.91,0:00:20.50,Default,,0000,0000,0000,,We specify our search term with the 'q' parameter. You can specify Dialogue: 0,0:00:20.50,0:00:24.80,Default,,0000,0000,0000,,You can specify a more complicated search term by URL escaping it. Dialogue: 0,0:00:24.80,0:00:27.80,Default,,0000,0000,0000,,There are many versions of the API Dialogue: 0,0:00:27.80,0:00:34.41,Default,,0000,0000,0000,,which we can specify which version we want to use using the 'v' parameter, or a special header. Dialogue: 0,0:00:34.41,0:00:39.47,Default,,0000,0000,0000,,Since there are many cute puppy videos on YouTube, and we don't want to handle them all at once, Dialogue: 0,0:00:39.47,0:00:44.68,Default,,0000,0000,0000,,we can specify how many we want by using 'max-results.' Dialogue: 0,0:00:44.68,0:00:48.57,Default,,0000,0000,0000,,Since we only want 10 at once, but we might want to page to the next 10, Dialogue: 0,0:00:48.57,0:00:53.99,Default,,0000,0000,0000,,we can look at the feed that's returned to the API for a 'link' element with 'rel' equals 'next' Dialogue: 0,0:00:53.99,0:00:58.40,Default,,0000,0000,0000,,This will identify the next page of results, and is the proper way of paging through a feed. Dialogue: 0,0:00:58.40,0:01:04.40,Default,,0000,0000,0000,,If you look at that 'next' link, you'll notice it has a 'start-index' parameter, which identifies the beginning of the next page Dialogue: 0,0:01:04.40,0:01:10.84,Default,,0000,0000,0000,,However, you should not try to set this parameter manually and instead always extract the value of the 'next' link from the feed Dialogue: 0,0:01:10.84,0:01:15.63,Default,,0000,0000,0000,,Now let's talk about some other query parameters that you can use with the YouTube API Dialogue: 0,0:01:15.63,0:01:21.93,Default,,0000,0000,0000,,First, we're going to talk about 'orderby'. By default, results are returned in order of relevance Dialogue: 0,0:01:21.93,0:01:28.80,Default,,0000,0000,0000,,but you can also have them ordered by rating, view count, and the date they were published. Dialogue: 0,0:01:28.80,0:01:34.47,Default,,0000,0000,0000,,You can also search for all the videos uploaded by a particular YouTube user with the 'author' parameter. Dialogue: 0,0:01:34.47,0:01:37.77,Default,,0000,0000,0000,,This is equivalent to retrieving their uploads feed. Dialogue: 0,0:01:37.77,0:01:41.94,Default,,0000,0000,0000,,In version 2 of the API, we added location based search Dialogue: 0,0:01:41.94,0:01:49.30,Default,,0000,0000,0000,,where you can pass latitude and longitude information and find videos that occurred near that point. Dialogue: 0,0:01:49.30,0:01:52.71,Default,,0000,0000,0000,,Since a large number of videos only have descriptive locations, such as London, Dialogue: 0,0:01:52.71,0:01:58.54,Default,,0000,0000,0000,,if you only wish for videos with explicit latitude and longitude information to be returned, Dialogue: 0,0:01:58.54,0:02:02.51,Default,,0000,0000,0000,,add an exclamation point to your query. Dialogue: 0,0:02:02.51,0:02:10.03,Default,,0000,0000,0000,,To only show embeddable videos, such as for embedding on an external webpage, use the 'format' parameter. Dialogue: 0,0:02:10.03,0:02:14.40,Default,,0000,0000,0000,,If you only want results in a specific language, you can use language restrict. Dialogue: 0,0:02:14.40,0:02:21.67,Default,,0000,0000,0000,,Note this is only for video metadata, and not the audio track of the video Dialogue: 0,0:02:21.67,0:02:24.73,Default,,0000,0000,0000,,You can also specify a safeSearch value which defaults to 'moderate', Dialogue: 0,0:02:24.73,0:02:31.97,Default,,0000,0000,0000,,but can also be 'strict' or 'none' for filtering restricted content. Dialogue: 0,0:02:31.97,0:02:34.20,Default,,0000,0000,0000,,Some videos cannot be played in certain locales. Dialogue: 0,0:02:34.20,0:02:38.97,Default,,0000,0000,0000,,You can specify the locale of your user by passing in their country code or their IP address Dialogue: 0,0:02:38.97,0:02:41.31,Default,,0000,0000,0000,,in which case we'll figure out their country code for you. Dialogue: 0,0:02:41.31,0:02:46.17,Default,,0000,0000,0000,,Note this is only to improve the user experience, as it will filter out videos they cannot play. Dialogue: 0,0:02:46.17,0:02:52.33,Default,,0000,0000,0000,,Using this parameter will not affect the videos that they can play. Dialogue: 0,0:02:52.33,0:02:57.27,Default,,0000,0000,0000,,YouTube has a number of video categories, such as Comedy, News and Politics, and more. Dialogue: 0,0:02:57.27,0:03:03.93,Default,,0000,0000,0000,,If we only wanted videos in the Comedy category, we can use the 'category' parameter to retrieve them. Dialogue: 0,0:03:03.93,0:03:08.71,Default,,0000,0000,0000,,If you are familiar with other Google Data APIs, you can also use the below syntax. Dialogue: 0,0:03:08.71,0:03:18.30,Default,,0000,0000,0000,,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' Dialogue: 0,0:03:18.30,0:03:23.67,Default,,0000,0000,0000,,Note that the video category started with an uppercase letter, whereas tags are all lowercase. Dialogue: 0,0:03:23.67,0:03:27.87,Default,,0000,0000,0000,,This means that the above search is for all videos in the Comedy category, Dialogue: 0,0:03:27.87,0:03:33.23,Default,,0000,0000,0000,,whereas the below search is for videos that have the tag 'comedy'. Dialogue: 0,0:03:33.23,0:03:37.43,Default,,0000,0000,0000,,You can also mix and match to combine the different query parameters we have discussed here. Dialogue: 0,0:03:37.43,0:03:41.73,Default,,0000,0000,0000,,For example, if you want to query for kitten videos in the Comedy category Dialogue: 0,0:03:41.73,0:03:47.72,Default,,0000,0000,0000,,that are embeddable on external webpages, you could use this query. Dialogue: 0,0:03:47.72,0:03:52.00,Default,,0000,0000,0000,,YouTube also provides lists of popular videos Dialogue: 0,0:03:52.00,0:03:55.33,Default,,0000,0000,0000,,These are exposed in the API as standard feeds. Dialogue: 0,0:03:55.33,0:04:01.63,Default,,0000,0000,0000,,Such as the top rated videos, the most viewed videos, and the most discussed videos. Dialogue: 0,0:04:01.63,0:04:06.37,Default,,0000,0000,0000,,We can also look at the top rated videos that were uploaded this week using the 'time' parameter. Dialogue: 0,0:04:06.37,0:04:13.53,Default,,0000,0000,0000,,We could also look at the top rated videos this month, or today. Dialogue: 0,0:04:13.53,0:04:21.20,Default,,0000,0000,0000,,You are also able to look at only the top rated videos in this particular category, such as Comedy. Dialogue: 0,0:04:21.20,0:04:25.03,Default,,0000,0000,0000,,Note that this is different from using the 'category' query parameter we talked about earlier. Dialogue: 0,0:04:25.03,0:04:29.70,Default,,0000,0000,0000,,The above feed is the top 100 rated videos in the Comedy category. Dialogue: 0,0:04:29.70,0:04:38.53,Default,,0000,0000,0000,,Whereas the bottom is -- of the top 100 rated videos on YouTube, which ones are in the Comedy category. Dialogue: 0,0:04:38.53,0:04:48.28,Default,,0000,0000,0000,,You can also look at regional versions of the different standard feeds, such as the top rated Comedy videos in Japan. Dialogue: 0,0:04:48.28,0:04:51.17,Default,,0000,0000,0000,,Hopefully, you're getting pretty excited about using the YouTube API Dialogue: 0,0:04:51.17,0:04:56.87,Default,,0000,0000,0000,,But before you get started, we want to go over a few simple caveats. Dialogue: 0,0:04:56.87,0:05:04.30,Default,,0000,0000,0000,,You cannot retrieve more than 1000 videos in a video search feed. This is the same as YouTube.com. Dialogue: 0,0:05:04.30,0:05:07.34,Default,,0000,0000,0000,,The openSearch totalResults value is an approximation. Dialogue: 0,0:05:07.34,0:05:14.13,Default,,0000,0000,0000,,This is part of why you should not do pagination manually, but instead use the 'next' link. Dialogue: 0,0:05:14.13,0:05:18.10,Default,,0000,0000,0000,,Let's go back to our earlier example about searching for cute puppy videos. Dialogue: 0,0:05:18.10,0:05:23.45,Default,,0000,0000,0000,,Because YouTube is a large video website, the search information may be cached. Dialogue: 0,0:05:23.45,0:05:28.13,Default,,0000,0000,0000,,This means that the most recently uploaded cute puppy videos may not be displayed in the results. Dialogue: 0,0:05:28.13,0:05:32.03,Default,,0000,0000,0000,,It also means that the information in these videos, such as the title and description, Dialogue: 0,0:05:32.03,0:05:35.97,Default,,0000,0000,0000,,may take a couple hours to be updated in the search index. Dialogue: 0,0:05:35.97,0:05:43.10,Default,,0000,0000,0000,,Also, statistics about the video, such as view count and favorite information may not be up to date. Dialogue: 0,0:05:43.10,0:05:50.37,Default,,0000,0000,0000,,For videos uploaded as private, and later made public, it will take even longer to enter into the search index. Dialogue: 0,0:05:50.37,0:05:55.23,Default,,0000,0000,0000,,What if you know the ID of a video you want to retrieve information on. Dialogue: 0,0:05:55.23,0:06:01.47,Default,,0000,0000,0000,,Similar to searching for videos on YouTube, this information will be cached. Dialogue: 0,0:06:01.47,0:06:07.57,Default,,0000,0000,0000,,This is also true if you retrieve it through the uploads feed for a user when you're not authenticated as them. Dialogue: 0,0:06:07.57,0:06:16.27,Default,,0000,0000,0000,,However, if you do authenticate as them, you will retrieve uncached information, which will be fresh. Dialogue: 0,0:06:16.27,0:06:20.17,Default,,0000,0000,0000,,Also, if you retrieve the uploads feed as the user, while authenticating as that user, Dialogue: 0,0:06:20.17,0:06:25.38,Default,,0000,0000,0000,,you will receive information about videos that is not cached. Dialogue: 0,0:06:25.38,0:06:30.90,Default,,0000,0000,0000,,This means it will the most recent information that YouTube has. It will be ordered by the published time. Dialogue: 0,0:06:30.90,0:06:34.60,Default,,0000,0000,0000,,However, if you add a query parameter, such as 'orderby' to this feed, Dialogue: 0,0:06:34.60,0:06:41.08,Default,,0000,0000,0000,,even though you're authenticated, the results will be cached. Dialogue: 0,0:06:41.08,0:06:46.13,Default,,0000,0000,0000,,Two query parameters that will not affect the caching process, are start-index and max-results, Dialogue: 0,0:06:46.13,0:06:50.13,Default,,0000,0000,0000,,so you can still page through a feed. Dialogue: 0,0:06:50.13,0:06:52.53,Default,,0000,0000,0000,,If you are using one of our provided client libraries, Dialogue: 0,0:06:52.53,0:06:56.84,Default,,0000,0000,0000,,there will be objects and methods which will help you build search queries on YouTube. Dialogue: 0,0:06:56.84,0:07:01.00,Default,,0000,0000,0000,,Please check the documentation for these client libraries for specifics. Dialogue: 0,0:07:01.00,0:07:07.30,Default,,0000,0000,0000,,All the information in this video is also available in our documentation on code.google.com. Dialogue: 0,0:07:07.30,9:59:59.99,Default,,0000,0000,0000,,Thanks for watching!