Today we announced the launch of YouTube Direct, a new tool built on top of YouTube's public APIs that enables any developer to solicit video submissions on their website, powered by YouTube.

Users upload their videos directly on the developer's website, after which the developer can review the submissions and select the best ones to showcase. Since these videos live on YouTube, users are able to reach YouTube's large user base directly while also getting broader exposure and editorial validation for the videos they create.

Although YouTube Direct was originally created with our news partners in mind, we believe that other developers and website owners can benefit from it as well. To put YouTube Direct in the hands of as many developers as possible, we open sourced the bulk of the code and designed it to run on Google App Engine - Google's scalable hosting platform. This enables developers to easily deploy their own instance of the tool and take advantage of App Engine's scalability and low cost. The videos themselves are served from the same infrastructure that powers YouTube.com.





Visit YouTube Direct for Developers page to read more about it or go directly to the project page to download the code. As always, we'd love to hear your feedback on this new tool. Drop us a line in YouTube's Developer Forum.
Today we announced the launch of YouTube Direct, a new tool built on top of YouTube's public APIs that enables any developer to solicit video submissions on their website, powered by YouTube.

Users upload their videos directly on the developer's website, after which the developer can review the submissions and select the best ones to showcase. Since these videos live on YouTube, users are able to reach YouTube's large user base directly while also getting broader exposure and editorial validation for the videos they create.

Although YouTube Direct was originally created with our news partners in mind, we believe that other developers and website owners can benefit from it as well. To put YouTube Direct in the hands of as many developers as possible, we open sourced the bulk of the code and designed it to run on Google App Engine - Google's scalable hosting platform. This enables developers to easily deploy their own instance of the tool and take advantage of App Engine's scalability and low cost. The videos themselves are served from the same infrastructure that powers YouTube.com.





Visit YouTube Direct for Developers page to read more about it or go directly to the project page to download the code. As always, we'd love to hear your feedback on this new tool. Drop us a line in YouTube's Developer Forum.

While we don't normally call out new releases of the Google Data YouTube API on this blog, we wanted to draw specific attention to the version that has just been pushed out to our staging servers. There are two specific changes that we'd like to give our developers and partners a chance to test before they go live. Both changes affect important areas of the API: ClientLogin authentication, and playback URLs in media:content entries.

We fully intend for the changes to be backwards compatible, and from the developer's perspective you should not have to change any code. But testing your code is always a best practice, so if you rely on ClientLogin or retrieving media playback URLs from the Google Data YouTube API, please repoint your code to http://stage.gdata.youtube.com and confirm functionality.

Any incompatibilities should be reported as soon as possible in our YouTube API Developer Forum. We expect to move the changes from the staging environment into production on November 17.
While we don't normally call out new releases of the Google Data YouTube API on this blog, we wanted to draw specific attention to the version that has just been pushed out to our staging servers. There are two specific changes that we'd like to give our developers and partners a chance to test before they go live. Both changes affect important areas of the API: ClientLogin authentication, and playback URLs in media:content entries.

We fully intend for the changes to be backwards compatible, and from the developer's perspective you should not have to change any code. But testing your code is always a best practice, so if you rely on ClientLogin or retrieving media playback URLs from the Google Data YouTube API, please repoint your code to http://stage.gdata.youtube.com and confirm functionality.

Any incompatibilities should be reported as soon as possible in our YouTube API Developer Forum. We expect to move the changes from the staging environment into production on November 17.

It's been several years since we've released the Google Data-based YouTube API, and in that time we've been encouraging developers who used the legacy YouTube API to upgrade before we pull the metaphoric plug on that older version. At this point, all but a handful of holdouts have upgraded, and as of November 11, 2009, the legacy YouTube API will cease operation.

If you're using one of our YouTube API client libraries, then you're definitely making use of the modern Google Data YouTube API. If you're manually making HTTP requests to a URL whose hostname contains gdata.youtube.com, then you're also good to go. If you think you might still be using the legacy YouTube API but aren't sure, take a look at some of the example legacy API calls in this migration guide. If it turns out that you are still using the older API, then the migration guide will give you the information you need to upgrade – and be sure to do so before November 11!
It's been several years since we've released the Google Data-based YouTube API, and in that time we've been encouraging developers who used the legacy YouTube API to upgrade before we pull the metaphoric plug on that older version. At this point, all but a handful of holdouts have upgraded, and as of November 11, 2009, the legacy YouTube API will cease operation.

If you're using one of our YouTube API client libraries, then you're definitely making use of the modern Google Data YouTube API. If you're manually making HTTP requests to a URL whose hostname contains gdata.youtube.com, then you're also good to go. If you think you might still be using the legacy YouTube API but aren't sure, take a look at some of the example legacy API calls in this migration guide. If it turns out that you are still using the older API, then the migration guide will give you the information you need to upgrade – and be sure to do so before November 11!

For the longest time, official YouTube video embed codes have contained embarrassingly malformed URLs; the first URL parameter (at the end of URLs) should always start with a ? character, but our URL parameters begin with &. That looks something like this:

http://www.youtube.com/v/0XjwoVqM_qE&feature=player_embedded&fs=1 (incorrect)
http://www.youtube.com/v/0XjwoVqM_qE?feature=player_embedded&fs=1 (correct)

Fortunately, we've found a way to use correct URLs without breaking old browsers and we can't wait to do it.

Speaking of changes to the embed code, we'll also be tweaking the HTML content. The new YouTube embed code is leaner and still works on everything from ancient desktop browsers to modern smart phones. You won't find another snippet of HTML that's as battle-tested and mother-approved! Here's a preview of the new, streamlined format:








And here's what the HTML looks like:

<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/0XjwoVqM_qE?color1=0xb1b1b1&color2=0xcfcfcf&hl=en&feature=player_embedded&fs=1">
<param name="allowFullScreen" value="true">
<param name="allowScriptAccess" value="always">
<embed src="http://www.youtube.com/v/0XjwoVqM_qE?color1=0xb1b1b1&color2=0xcfcfcf&hl=en&feature=player_embedded&fs=1"
type="application/x-shockwave-flash" allowfullscreen="true"
allowScriptAccess="always" width="425" height="344">
</object>


If you grab YouTube embed codes by hand from YouTube.com, or from the YouTube Player APIs or oEmbed, you'll start getting this updated HTML soon. As for all the embeds already on the web: worry not, those will continue to work forever.

We have some good news for developers who integrate YouTube videos into their ActionScript 3 Flash applications: the official YouTube Chromeless Player API has been updated to natively support ActionScript 3!

Previous to this release, ActionScript 3 developers had to rely on wrapper libraries that bridged the gap between the native ActionScript 2 API and their own ActionScript 3 code. We're thrilled that intrepid developers were able to patch things together on their own and share their code with the rest of the community. Now that there's official support for using the chromeless player from ActionScript 3, everyone should have more time to focus on writing compelling Flash applications, rather than dealing with the unique issues that cross-language coding entails.

Please check out our ActionScript 3 documentation, and let us know what you think of the new API in our developer forum.

With the launch of ActionScript 3 support, we're officially deprecating the ActionScript 2 YouTube Chromeless Player API. As per our YouTube API deprecation policy, detailed in our Terms of Service, we will continue to operate the ActionScript 2 API for a period of three years (until October 14, 2012).

Cheers,
-The YouTube API Team
We have some good news for developers who integrate YouTube videos into their ActionScript 3 Flash applications: the official YouTube Chromeless Player API has been updated to natively support ActionScript 3!

Previous to this release, ActionScript 3 developers had to rely on wrapper libraries that bridged the gap between the native ActionScript 2 API and their own ActionScript 3 code. We're thrilled that intrepid developers were able to patch things together on their own and share their code with the rest of the community. Now that there's official support for using the chromeless player from ActionScript 3, everyone should have more time to focus on writing compelling Flash applications, rather than dealing with the unique issues that cross-language coding entails.

Please check out our ActionScript 3 documentation, and let us know what you think of the new API in our developer forum.

With the launch of ActionScript 3 support, we're officially deprecating the ActionScript 2 YouTube Chromeless Player API. As per our YouTube API deprecation policy, detailed in our Terms of Service, we will continue to operate the ActionScript 2 API for a period of three years (until October 14, 2012).

Cheers,
-The YouTube API Team

We first announced our new API upload infrastructure back in June and asked developers to test their YouTube API code against our staging environment.

Since then, we've started deploying the new upload infrastructure to production machines in a phased manner. Last month, we transitioned browser-based API uploads to the new servers, and have been closely monitoring performance and error rates to ensure that there were no unintended side effects.

We're now ready to begin the transition for direct uploads. Starting today, a small percentage of direct uploads traffic will automatically be routed to our new servers. We will be monitoring traffic over the next few weeks and gradually increasing the traffic that the new servers receive until we have fully completed the migration.

As a developer, you won't have to make any changes in your code to take advantage of the increased reliability and bug fixes found in the new infrastructure. While we do expect that this new infrastructure will be fully backwards compatible, if you do notice any change in your application's behavior with regard to direct uploads, please let us know in our developer group.

Cheers,
-The YouTube API Team
We first announced our new API upload infrastructure back in June and asked developers to test their YouTube API code against our staging environment.

Since then, we've started deploying the new upload infrastructure to production machines in a phased manner. Last month, we transitioned browser-based API uploads to the new servers, and have been closely monitoring performance and error rates to ensure that there were no unintended side effects.

We're now ready to begin the transition for direct uploads. Starting today, a small percentage of direct uploads traffic will automatically be routed to our new servers. We will be monitoring traffic over the next few weeks and gradually increasing the traffic that the new servers receive until we have fully completed the migration.

As a developer, you won't have to make any changes in your code to take advantage of the increased reliability and bug fixes found in the new infrastructure. While we do expect that this new infrastructure will be fully backwards compatible, if you do notice any change in your application's behavior with regard to direct uploads, please let us know in our developer group.

Cheers,
-The YouTube API Team


{"provider_url": "http://www.youtube.com/",
"title": "Auto-Tune the News #8: dragons. geese. Michael Vick. (ft. T-Pain)",
"html": "embed code",
...}
oEmbed is a pretty slick way to embed multimedia for a link. For example with a request like this:

You get a response like this:
{"provider_url": "http://www.youtube.com/",
"title": "Auto-Tune the News #8: dragons. geese. Michael Vick. (ft. T-Pain)",
"html": "embed code",
...}
The value for the "html" key is all you need to insert into your webpage to render an embedded YouTube video:

Check out the documentation at oEmbed.com for more information.

Getting your YouTube web or client application up and running is only half the battle. We know that you'll also want to monitor your application to see how it's performing. Our new Developer Dashboard shows you at a glance the number of API requests, playbacks, uploads and errors that your app is generating. You can visualize the data using our interactive chart or download a file to process the data offline. To use the dashboard, you'll need to provide a developer key in your API requests and then pass the media URLs from the API responses to the standard embedded player or the chromeless player.
Getting your YouTube web or client application up and running is only half the battle. We know that you'll also want to monitor your application to see how it's performing. Our new Developer Dashboard shows you at a glance the number of API requests, playbacks, uploads and errors that your app is generating. You can visualize the data using our interactive chart or download a file to process the data offline. To use the dashboard, you'll need to provide a developer key in your API requests and then pass the media URLs from the API responses to the standard embedded player or the chromeless player.

You can log into the new Developer Dashboard at http://code.google.com/apis/youtube/dashboard/

Posted by Kuan Yong, YouTube APIs and Tools Team

In August last year, we launched the ability to add captions to your videos on YouTube. Now, you can do the same using the YouTube Data API.

With the new captions API, developers can create third-party apps that help users create, upload and manage the caption tracks of their YouTube videos. Each video can have multiple caption tracks, and multiple subtitle formats are supported.
In August last year, we launched the ability to add captions to your videos on YouTube. Now, you can do the same using the YouTube Data API.

With the new captions API, developers can create third-party apps that help users create, upload and manage the caption tracks of their YouTube videos. Each video can have multiple caption tracks, and multiple subtitle formats are supported.

Find out more in our Developer's Guide.

Posted by Christoph Schwab-Ganser, YouTube Engineering

Attention film buffs!

The American Film Institute (AFI) just launched a new video portal on AFI.com featuring hundreds of videos from its vast archives. AFI is utilizing YouTube's APIs in order to stream videos directly from AFI's ...
Attention film buffs!

The American Film Institute (AFI) just launched a new video portal on AFI.com featuring hundreds of videos from its vast archives. AFI is utilizing YouTube's APIs in order to stream videos directly from AFI's YouTube channel, as well as other great clips curated from YouTube. In addition to accessing the video content, users can post comments on the AFI.com video site as well as embed the videos on other sites, blogs and social networking pages.

The collection will be regularly augmented with videos selected from the AFI Archive, which contains 10,000 hours of material produced during AFI's 42-year history, much of which has never been seen by the general public. Be sure not to miss great clips such as "Alfred Hitchcock On Mastering Cinematic Tension" or "Steven Spielberg: The Toughest Thing For A Director".

We're thrilled that the YouTube APIs can help unlock such amazing material. Nice work, AFI!

Posted by George Strompolos, YouTube Partner Team

At Google I/O 2009, we demoed a nifty sample application that tracks updates to any number of YouTube user activity feeds. The technology behind the application is the Simple Update Protocol ...
At Google I/O 2009, we demoed a nifty sample application that tracks updates to any number of YouTube user activity feeds. The technology behind the application is the Simple Update Protocol (SUP), a simple and compact "ping feed" that enables your application to efficiently monitor changes to a large number of user activity feeds.

If you run a social network with tons of users who also happen to be active on YouTube, you should consider using SUP to let your users easily share their updates on YouTube with their friends through their social graph on your site. See the docs here.

Posted by Kuan Yong, YouTube APIs and Tools Team

The team has been working to improve the API upload infrastructure behind the scenes, and the new build is up at:

http://uploads2.gdata.youtube.com

Please do regression testing on your systems and report problems in our ...
The team has been working to improve the API upload infrastructure behind the scenes, and the new build is up at:

http://uploads2.gdata.youtube.com

Please do regression testing on your systems and report problems in our discussion forum.

Barring any major complications, this will begin rolling out to the production uploads URL (uploads.gdata.youtube.com) in two weeks.

Posted by Stephanie Liu, YouTube APIs and Tools Team

Wow, there's quite a bit of creative talent out there! It was hard to select from all the posts, but the winning haiku was from lionstone:

public void youtube ...
Wow, there's quite a bit of creative talent out there! It was hard to select from all the posts, but the winning haiku was from lionstone:

public void youtube
extends the community
return social change

Honorable mention goes to Ron (who already bought a ticket to the conference!):

Documentation -
cut, five, seven, five, season
form situation

We'll be seeing both of them at Google I/O tomorrow -- if you're coming as well, come say 'hi' to the team at Office Hours, at the Sandbox, and in our two sessions. If you can't make it, watch the Twitter stream during the conference and the videos that will be posted afterwards.

Posted by Stephanie Liu, YouTube APIs and Tools Team

Google I/O, our largest developer conference in San Francisco, CA, is just around the corner, and we'd love to see more YouTube developers there. We'll have two formal sessions, as well as office hours and lots of demos at the Developer Sandbox.
Google I/O, our largest developer conference in San Francisco, CA, is just around the corner, and we'd love to see more YouTube developers there. We'll have two formal sessions, as well as office hours and lots of demos at the Developer Sandbox.

Kuan, our Product Manager, will be giving a session about writing great, monetizable apps, and Jeff Fisher and Jochen Hartmann will be giving a session on the new social feeds.

Check out the rest of the great sessions and the schedule.

We have one free pass ($400 value) to give away, so if you'll be in the area, tell us why you want to go in this forum thread. We'll pick the worthiest person by the end of the week (hint: Jeff really likes Haikus :).

Posted by Stephanie Liu, YouTube APIs and Tools Team

In an alternate universe (where I have a goatee) I may be a voice actor instead of a Googler. However, since we live in this universe, the best I can do is make you a screencast about the YouTube API. Specifically, this video discusses the various search options we have in our Data API and the various limitations and caveats to keep in mind while integrating it into your program or website.
In an alternate universe (where I have a goatee) I may be a voice actor instead of a Googler. However, since we live in this universe, the best I can do is make you a screencast about the YouTube API. Specifically, this video discusses the various search options we have in our Data API and the various limitations and caveats to keep in mind while integrating it into your program or website.

If our API documentation is like the printed manual in the box of a new purchase that you never read, think of this video as the one-page laminated card with pretty pictures on it telling you not to get crushed by a bookshelf or hurt your back. Enjoy!


As promised in the previous blog post, I was given the task of making our Chow Down Gdata sample a little faster. It would sometimes take a while to load restaurant information due to the requests to YouTube and Picasa Web Albums taking a while to be processed on the backend. Since this would cause the user to sometimes see a "loading" bar for several seconds; something had to be done.
As promised in the previous blog post, I was given the task of making our Chow Down Gdata sample a little faster. It would sometimes take a while to load restaurant information due to the requests to YouTube and Picasa Web Albums taking a while to be processed on the backend. Since this would cause the user to sometimes see a "loading" bar for several seconds; something had to be done.



Originally, the application used the Python client library to retrieve information from YouTube and PWA and then stored it inside of memcache. The new solution is to instead retrieves these feeds directly in the browser using the json-in-script support of the Google Data APIs. This approach worked well for the Chow Down application since we were not retrieving any private information for use in this application and so did not need to authenticate as a user.

Another benefit of using the JSON feeds is that the browser can asynchronously request results from both YouTube and PWA at the same time and render the results as soon as they are returned. This helps decrease the "perceived load time" that the user experiences since they are seeing information start to be loaded instead of just watching a progress bar.

The code for the entire sample is available on code.google.com:

http://code.google.com/p/gdata-samples/source/browse/trunk/chow-down-gdata/

But you can see all of the logic for retrieving the feeds using JavaScript in the ajax_restaurant_info template:

http://code.google.com/p/gdata-samples/source/browse/trunk/chow-down-gdata/src/templates/ajax_restaurant_info.html

The code makes use of the jQuery JavaScript library in order to remain compact and compatible.

So if your site is using the Data APIs of one or more Google properties and you don't need authentication, considering switching to the JSON feeds to improve perceived latency and let your pages load the AJAXy way.

Recently I was given the task of modifying the Chow Down sample application (originally written to demonstrate how to implement the Google FriendConnect API on Google AppEngine) to include videos, pictures and search results in the restaurant detail pages. This task resulted in the creation of ...
Recently I was given the task of modifying the Chow Down sample application (originally written to demonstrate how to implement the Google FriendConnect API on Google AppEngine) to include videos, pictures and search results in the restaurant detail pages. This task resulted in the creation of Chow Down Gdata (full source code) which uses the YouTube Data API, the Picasa Web Albums API and the AJAX Search APIs.


Since everything was written in Python, using our Python client library was a no brainer. The first step was to add the necessary files and import statements. The application follows a standard MVC layout, so the next step was to create a new view called JsonRestaurantInfoView in views.py, which I then connected both to the ajax_restaurant_info.htmltemplate and also to the restaurants_info method in providers/restaurants.py.

The bulk of the modifications happen inside restaurants_info:

# Create client and query to execute a YouTube search:
gdata_youtube_client = gdata.youtube.service.YouTubeService();
query = gdata.youtube.service.YouTubeVideoQuery()
query.vq = "%s %s" % (restaurant.name, restaurant.city)
video_feed = gdata_youtube_client.YouTubeQuery(query)

# Grab the URL to the embeddable Flash player SWF (if embeddable)
swf_url = video_entry.GetSwfUrl()

if swf_url:
restaurant.player = """<object width="425" height="350">
<param name="movie" value="%s"></param>
<embed src="%s" type="application/x-shockwave-flash"
width="425" height="350"></embed></object>""" %
(swf_url, swf_url)

But wait! We are not done yet. Let's also look for pictures for this restaurant in Picasa:
gdata_picasawebalbums_client = gdata.photos.service.PhotosService()
query_parameters = map(urllib.quote, [restaurant.name, restaurant.city]);

# Fetch a feed of 10 thumbnails, 32x32 pixels in size and cropped to a square
photo_feed = gdata_picasawebalbums_client.GetFeed(
"/data/feed/api/all?q=%s%%20%s&max-results=10&thumbsize=32c" %
(query_parameters[0], query_parameters[1]))

We store all the new metadata in the restaurant object that ends up being passed to the template. To direct users there from the search page, I added a simple show_restaurant_info function which is triggered when a user clicks on the restaurant title in the search listing. While I was in the templates/index.html file, I also added the ajax_api_restaurant_info function which fetches blog, web, news and book search information about the restaurant.

Check out the full source code to get the full picture including information about how this data was also cached.

In the next article, Jeff Fisher is going to talk about how to optimize the performance for this application by using JavaScript.

Enjoy a few new tidbits in the latest release.



Yup, the same way you can search for videos and channels , you can now use the API to search for playlists ...
Enjoy a few new tidbits in the latest release.

Search for playlists

Yup, the same way you can search for videos and channels , you can now use the API to search for playlists:
http://gdata.youtube.com/feeds/api/playlists/snippets?q=soccer&v=2
The query above will return a list of playlist snippets that match the query 'soccer'. Searching in playlists is an excellent way to find YouTube videos about a specific point of interest (e.g. dancing, cooking, sports etc.).

Time filtering for video search

You can now restrict the video search result to a specific time interval (today, this_week, this_month, all_time):

http://gdata.youtube.com/feeds/api/videos?q=soccer&time=today&v=2

The default is 'all_time'.

More results

You can now request past the 100th video in a playlist and past the 200th video in a favorite list. Additionally, you can now get 1000 videos in a search feed instead of 999! Enjoy that last video, guys.

As always, post in the forum if you have any feedback or questions!

Posted by Daniel Danciu, Software Engineer

As you may have heard, YouTube has been getting more social lately. Our activity feeds help your users stay up-to-date on the cool channels and videos that their friends (or anyone else, for that matter) have been uploading, subscribing to, adding as favorites and so forth.
As you may have heard, YouTube has been getting more social lately. Our activity feeds help your users stay up-to-date on the cool channels and videos that their friends (or anyone else, for that matter) have been uploading, subscribing to, adding as favorites and so forth.


But we don't just care about YouTube users. We also care about developers. And we want you to have time to be more social, too.


With that in mind, Jeff Fisher and I wrote a hands-on tutorial that explains how to build the YouTubeActivityViewer, a PHP application that uses the new activity feeds. The application uses our PHP client library with jQuery. If you're still not ready to rush out and socialize, you can also build in a caching system with memcache.


http://google-gdata.googlecode.com/svn/trunk/clients/cs/docs/AdditionalContent/YouTubeLinqExamples.html

Last, but not least, there is the Notifier for YouTube sample application, which showcases the activity feeds YouTube is exposing. You can subscribe to events from your friends and other YouTube users and get notified whenever they leave their marks in the YouTube universe. The ...
Posted by Frank Mantek, Google Data APIs Team

The new .NET SDK is released and available for download here:

http://code.google.com/p/google-gdata/downloads/list

There's now updated support for YouTube V2 and a new vertical object model that allows you to use local LINQ queries. Please go through the Google.YouTube namespaces and see what's new there. We have some documentation for it here:

http://google-gdata.googlecode.com/svn/trunk/clients/cs/docs/AdditionalContent/YouTubeLinqExamples.html

Last, but not least, there is the Notifier for YouTube sample application, which showcases the activity feeds YouTube is exposing. You can subscribe to events from your friends and other YouTube users and get notified whenever they leave their marks in the YouTube universe. The sample is also available as a separate download.

The complete release notes can be found here:

http://google-gdata.googlecode.com/svn/docs/RELEASE_NOTES.HTML

which also lists all the bugs that were fixed in this release. Report new ones here:

http://code.google.com/p/google-gdata/issues/list

Posted by Jochen Hartmann, YouTube APIs and Tools Team


If you are using the PHP Client Library to upload your videos to YouTube.com you may have had to deal with memory issues, such as the common ...
Posted by Jochen Hartmann, YouTube APIs and Tools Team


If you are using the PHP Client Library to upload your videos to YouTube.com you may have had to deal with memory issues, such as the common Fatal error: Allowed memory size of ... bytes exhausted error message.

I am happy to announce that as of version 1.7.6 of the client library, this should no longer be a problem. Jeff Fisher and I have added support for streaming large video files to our API in manageable 1 MB chunks. The change is completely transparent, so you won't need to do anything besides upgrade your copy of the client library.

Prior to this change, our client library used to rely solely on the Zend_Http_Client object to handle HTTP communication between servers. The client makes requests by reading the entire body of your HTTP POST message into a string, which then gets sent to our API server. This behavior is perfectly acceptable for normal use since most of the time we are just sending XML strings or small media files such as images, but doesn't work quite so well for uploading 1 GB video files.

To address this problem, I designed a Zend_Gdata_MediaMimeStream object which only stores a handle to the video file being uploaded. Jeff built a Zend_Gdata_HttpAdapterStreamingSocket which then reads from the media stream in 1 MB chunks and sends to the socket until the entire message is read. We have tested this code extensively and are always open to feedback on how to improve performance issues in our client library, so check out the source code if you are interested.

While I have your attention, let me also share another trick for those obsessed with efficiency: If you are only interested in working with the raw XML instead of the complete Zend_Gdata object model, you can flip a minor switch that is available in all of our service classes (Zend_Gdata_YouTube, Zend_Gdata_Docs, etc.):

$yt = new Zend_Gdata_YouTube(); $yt->useObjectMapping(false); $xmlString = $yt->getRecentlyFeaturedVideoFeed(); echo gettype($xmlString); # will return 'string'

As you can see in the snippet above, the $xmlString variable is now just a regular string instead of a Zend_Gdata_VideoFeed object. My testing shows that this can make fetching video feeds from YouTube faster by up to 35 times. Of course you would need to add a little bit of time parsing the XML with the tool of your choice (XPath, etc.). I should also add that those interested in parsing XML without the aid of the client library may want to check out the Backward Compatibility Guidelines for the YouTube Data API.

Posted by Stephanie Liu, YouTube APIs and Tools Team

YouTube has been getting more social lately, using activity feeds to make it easier to find cool videos and channels that your YouTube friends are favoriting, rating, subscribing to, etc. But what if all your friends aren't on YouTube, but rather on social network / site XYZ?
Posted by Stephanie Liu, YouTube APIs and Tools Team

YouTube has been getting more social lately, using activity feeds to make it easier to find cool videos and channels that your YouTube friends are favoriting, rating, subscribing to, etc. But what if all your friends aren't on YouTube, but rather on social network / site XYZ?

Well, my friends, the API has come out of its awkward teenage years, and now has more sophisticated social skills to help. Activities like favoriting, uploading, commenting, and more can now be integrated into the social context of your choice. Check out the docs for the new user activity feed and friend activity feed.

Before you ask, the user activity feed is fully customizable by the user, and the corresponding feed through the API respects all privacy settings. So users still have full control over what they make available in their recent activity feed.

We think some cool apps can be made with these feeds -- like the obvious social network / feed aggregator integrations, to notification apps, to novel data views. We can't wait to see what you guys make!

Get started by perusing the docs and playing with the sample. Besides the protocol guide, we've also updated the Java and PHP guides with helpful snippets. An activity viewer sample written in PHP and its source code is also available for you to play with.

As always, let us know if you have any questions or feedback in the forum.

PS. If you want to socialize with the team in person, come to Google I/O, where we'll be giving a session on "Going social with the YouTube APIs"!

Posted by Jeff Fisher, YouTube APIs and Tools Team

We know developers really like AS3, but sometimes they have difficulty getting our players to work correctly. To make this process easier for the Flashy/Flexy crowd, the awesome Ben Longoria has given us ...
Posted by Jeff Fisher, YouTube APIs and Tools Team

We know developers really like AS3, but sometimes they have difficulty getting our players to work correctly. To make this process easier for the Flashy/Flexy crowd, the awesome Ben Longoria has given us TubeLoc.



TubeLoc is an AS3 wrapper around the Player API that uses LocalConnection to communicate to the AS2 YouTube SWFs. It takes this a step further by also providing Flex components to make inserting a YouTube video and controls easy.

Ready to get started? First read the article that goes in depth on how to use TubeLoc. Next, visit the project page to download the code and play with the live demos. Finally, tell us what you think on the forum. Thanks Ben!

Update (Nov. 2013): The information in this blog post is out of date; the current best practice for embedding YouTube videos in an iOS application is to use the YouTube iframe Player within a UIWebView container.
Update (Nov. 2013): The information in this blog post is out of date; the current best practice for embedding YouTube videos in an iOS application is to use the YouTube iframe Player within a UIWebView container.
Posted by Kuan Yong, YouTube APIs and Tools Team
The YouTube APIs Terms of Service permits commercial use of the APIs under certain conditions, and in most cases, as long as you play fair, you are free (and highly encouraged) to develop great iPhone apps using the YouTube APIs and sell them in the iTunes App Store.

An iPhone app that uses the YouTube APIs typically needs to do two things:
  • Call the YouTube API Data API to search videos, get video metadata, etc. You should use our Objective C client library instead of trying to construct the HTTP request or parse the response by hand.
  • Invoke the native YouTube player on the iPhone to play videos.
There are at least two ways to play YouTube videos in your iPhone app (that don't run afoul of Apple's SDK rules). The easier way requires just one line of code but it involves quitting your app and launching the full YouTube app on the phone. The better way needs a little more setup but provides a seamless way of taking the user to the YouTube player and back to your app. Note that these two methods work only on an actual device, not in the iPhone simulator, since the latter does not have a YouTube player.


Method 1: Open the YouTube play page URL (Easier)

1. Grab the video url from the media tag in the API response with the application/x-shockwave-flash type. It should look something like this:

http://www.youtube.com/v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM

If you don't see the c and d parameters in the URL, it's because you are not passing in your developer key and client ID in the request. While they are not mandatory for read requests, we highly recommend that you provide them in every API request.

2. Open the URL in your app by calling the openURL method on your UIApplication instance:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.youtube.com/v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM"]];


When your app calls openURL, it will quit and launch the full native YouTube app on the phone. After the video stops playing, the user remains in the YouTube app. The user has no easy way of getting back to your app.


Method 2: Embed the YouTube player in a UIWebView
No, the iPhone still doesn't do Flash, but if you haven't already noticed, the Safari browser on the iPhone is clever enough to turn any YouTube embed into a clickable thumbnail that launches the native YouTube player app on the phone. You can take advantage of this feature in your app by using a UIWebView. Here's how:

1. Set up a UIWebView in your app. You can make it part of a xib or create it programmatically. Size the UIWebView according to how large you want the clickable thumbnail to be.

2. Grab the video url using the same method as the one described above.

3. Call the loadHTMLString:baseURL: method on the UIWebView instance with some carefully constructed HTML that contains the YouTube embedded player code snippet and some supporting HTML to make sure that the video thumbnail appears correctly. Set the base URL to the URL of your website (it doesn't do anything here -- ordinarily UIWebView uses it to handle relative URL links correctly).

The best way to illustrate this is with a code snippet. Note the use of the viewport HTML meta parameter and the consistent use of width and height parameters throughout.

// webView is a UIWebView, either initialized programmatically or loaded as part of a xib.

NSString *htmlString = @"<html><head>
<meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head>
<body style=\"background:#F00;margin-top:0px;margin-left:0px\">
<div><object width=\"212\" height=\"172\">
<param name=\"movie\" value=\"http://www.youtube.com/v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"></param>
<param name=\"wmode\" value=\"transparent\"></param>
<embed src=\"http://www.youtube.com/v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"
type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"212\" height=\"172\"></embed>
</object></div></body></html>";

[webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.your-url.com"]];

One of the biggest benefits of this approach is that your app does not have to quit in order for the video to start playing. In fact, the iPhone will keep your app running in the background while it fires up the YouTube player to play the video. After the video finishes playing (or when the user hits "Done"), the user is automatically taken back to your app. This experience is very similar to watching embedded YouTube videos in the iPhone Safari browser and is just as seamless.


Have fun writing the next killer iPhone app, and don't forget to list your app in the YouTube Project Gallery once it goes live in the App Store!

Coming up: Adding YouTube content to Android apps

Posted by Kuan Yong, YouTube APIs Product Manager

Money: it's on everyone's mind lately, and we know developers are no different. We understand that developers aren't just satisfied with creating the coolest YouTube mashup out there. They also want a way to sustain their efforts financially, and the trick is figuring out how to do so appropriately. That's why we've published a ...
Posted by Kuan Yong, YouTube APIs Product Manager

Money: it's on everyone's mind lately, and we know developers are no different. We understand that developers aren't just satisfied with creating the coolest YouTube mashup out there. They also want a way to sustain their efforts financially, and the trick is figuring out how to do so appropriately. That's why we've published a document that provides clear guidance on how you can monetize the apps you've built with the YouTube APIs. While it is not a substitute for reading our Terms of Service, it should point you to the clauses you should pay attention to and hopefully even give you some ideas for your next YouTube API-powered project.

So go ahead, launch the next great YouTube mashup, and monetize the hell out of it. And don't forget to tell us about your app at the YouTube Project Gallery.

Posted by Stephanie Liu, YouTube APIs and Tools Team

Last week, we had a grand ol' time troubleshooting some issues, chatting about the player, making some new friends, and salivating over a ...
Posted by Stephanie Liu, YouTube APIs and Tools Team

Last week, we had a grand ol' time troubleshooting some issues, chatting about the player, making some new friends, and salivating over a Dark Chocolate Bacon Cupcakes recipe. So, we'll be holding office hours again next week, same bat time, same bat channel.

Where: irc.freenode.net#youtube-api
When: Wednesday, February 4th, 1:00 - 3:00 pm PST
Who: Look for xirzec, stephliu, and jh_youtube

Let us know if you'd prefer a different time for future office hours, or just post your questions in our discussion forum.

Posted by Stephanie Liu, YouTube APIs and Tools Team

Starting next week, we'll be hosting live office hours on IRC ( irc.freenode.net channel #youtube-api). Come ask your questions, give feedback, gossip about the latest Atom Pub news, share best practices, or just hang out.
Posted by Stephanie Liu, YouTube APIs and Tools Team

Starting next week, we'll be hosting live office hours on IRC (irc.freenode.net channel #youtube-api). Come ask your questions, give feedback, gossip about the latest Atom Pub news, share best practices, or just hang out.

Where: irc.freenode.net#youtube-api
When: Wednesday, January 21st, 1:00 - 3:00 pm PST
Who: Look for xirzec, stephliu, and jh_youtube, we'll be the cool kids in the back :)

If you can't make it, no worries, you can still post, as always, in the discussion forum. You can also let us know what times would work better for you in the future. See you there!

UPDATE: Small change. We'll be hosting hours 1-3 PST, not PDT :) Also, for those of you who don't have IRC clients installed, you may want to use a web-based client like mibbit.com. Choose "Freenode" as the server, pick a nickname, and use #youtube-api as the channel.

Posted by Pamela Fox, Maps API Team

Hey YouTube folks! My name is Pamela Fox, and I hail from the Maps API world. I was charged with the task this year of creating the map for the ...
Posted by Pamela Fox, Maps API Team

Hey YouTube folks! My name is Pamela Fox, and I hail from the Maps API world. I was charged with the task this year of creating the map for the NORAD Santa Tracker (yes, Google even indexes Santa), and I decided to convert last year's JavaScript map into a Flex map. This meant converting every feature into Flex, including arguably the most important feature: displaying YouTube-hosted Santa Cam videos in the infowindows. The kiddies get a kick out of seeing Santa soaring, tumbling, and freewheeling through the endless diamond sky.

I wanted what I thought was a basic feature: using the embedded player to play 23 different YouTube videos in the same Flex app. I started with a straightforward implementation - using the SWFLoader Flex component with the source set to the URL of the YouTube video. But I noticed some funny behavior - the first video would load, but none after that. After some searching around, I discovered the reason for this: if the first loaded YouTube SWF isn't properly removed by calling its destroy method(), any subsequently loaded YouTube SWF won't play correctly. The solution is to call destroy() on the YouTube SWF - but wait a second, it's not that easy. Flex/AS3 SWFs cannot call methods on AS2 SWFs, and YouTube SWFs are indeed written in AS2.

After harassing various YouTube engineers and reading through the AS3 Chromeless Player wrapper code, I came up with the solution shown in the diagram below.



The Flex app uses SWFLoader to load in an AS2 SWF, which I call the "YouTube bridge". The YouTube bridge creates a LocalConnection, which is a way for any SWF to invoke methods on any other SWF that's open simultaneously on a computer. The bridge specifies what connection it can receive commands from, and then defines two functions that other SWFs can call - loadMovie() and dispose(). The loadMovie() function takes in a YouTube ID, creates a MovieClip and loads the YouTube movie into it. The dispose() function calls destroy() on that MovieClip, and then does various other cleanup operations. The Flex app then tells that same connection what method names it wants to invoke, either "loadMovie" or "dispose". Some snippets of the LocalConnection code are shown below:


// Flex
outBox = new LocalConnection();
outBox.send(outBoxName, "dispose");
outBox.send(outBoxName, "loadMovie", ids[counter]);

// AS2
var inbox = new LocalConnection();
inbox.connect(_root.boxName);
inbox.dispose = function () {
youtubeMC.destroy();
...
};


When I first coded this, I hard-coded a name for the connection name in the Flex + AS2. This meant that my app couldn't be used in multiple browsers at the same time, since all instances of the app would be sending and receiving messages from the same inbox, and they'd get awfully confused. To remedy that, I generate a random ID in the Flex app, pass that into the query string when loading the YouTube bridge, and then have the bridge use the value of the query parameter as the inbox name. A snippet of that code is shown below:


// Flex
outBoxName = String(new Date().getUTCMilliseconds());
swfLoader.load("youtubebridge.swf?boxName=" + outBoxName);

// AS2
inbox.connect(_root.boxName);


The full code (MXML + FLA) is available, and you can test out the demo app. Now that I've made it easy for you all, I hope to see some nifty YouTube/Flex mashups.. and maybe even some Youtube/Flex/Maps mashups!