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.