Tuesday, March 4, 2014

Committing to the YouTube Data API v3

Since the YouTube Data API v3 launch in 2012, many of you have used the v3 API to create integrations like Next Big Sound and Interesante.

The YouTube Data API v3 is now on the list of APIs identified in our deprecation policy, which means we will notify developers a year in advance before deprecating v3. Note, however, that some specific v3 features are excluded from this notice requirement. You can find the list here. As a reminder, v3 gives you the ability to get information about Freebase topics associated with the videos, more search features, improved client libraries support and much more.

To focus on improving v3, it’s time to say goodbye to our old friend, v2. In keeping with deprecation policy, most API functionality will remain available for use until April 20, 2015, so you have more than a year to move to the new API. See the deprecation policy in the Terms of Service for more details.

While v3 offers the majority of v2 functionality, there are currently a couple of tasks that can only be done with the older API. Specifically, applications that manage captions or that work with video comments still need to use the v2 API until modern equivalents are available. Our goal is to provide similar functionality well before the April 2015 shut-off date—please subscribe to this blog, the YouTube Data API v3 revision history page, or follow +YouTubeDev on Google+ to keep up-to-date.

If you’re a v2 developer who’s looking for help migrating to v3, the best place to start is with our documentation and FAQs. We've also made several videos that explain v3 concepts, such as registering for API access and handling authorization with OAuth 2.0.




Cheers,

Monday, December 16, 2013

Building on YouTube APIs in the cloud with Google Apps Script

There’s nothing better in this world than a great pairing, like coffee and donuts or bees and honey. Today there’s a new one to add to the list: Google Apps Script now has built in support for the YouTube Data v3 and YouTube Analytics APIs. If you haven’t yet heard of Google Apps Script, you’re missing out on an easy-to-use tool for integrating and automating common tasks across many of Google’s services. With less than half a screen’s worth of code in Google Apps Script’s cloud-based editor, you can:

  • Dynamically update a spreadsheet containing watch-time statistics for all of your channel's videos, with all the flexibility and power of Google Sheets to sort and slice that data
  • Create a live dashboard or scheduled email report about your channel's performance
  • Handle channel management tasks such as scheduling automatic bulletins or changing the visibility of a large number of videos from private to public
  • Automate playlist rotation without having to maintain a server or keep a computer for the sole purpose of running a script
Google Apps Script's cloud-based environment and autocomplete functionality make it easy to just open an editor, enable the YouTube APIs, and start writing code:



For functions that require OAuth 2.0 authorization, there’s no authorization code to write and no token management to deal with. Once your script is ready, just click “Run” and Google Apps Script will present you with an authorization dialog. Once you select the channel you want to authorize, the script will have all of the permissions it needs to operate on your behalf, running in the background at scheduled intervals if you so desire.

To get started, browse to Google Drive. Click “Create” and then choose “Script”. This will open a new browser tab to the Google Apps Script editor. Name your project and click on “Resources” and select “Advanced Google Services”:


Toggle the YouTube Data API and/or YouTube Analytics API on:


Note the message that these services must be enabled in the API console. Click the link to be taken to the Google Developer Console. The link in the message will take you to a specific API project created for this specific Apps Script. Scroll down and toggle on the YouTube APIs the script will use:


Switch back to the tab containing Google Apps Script and click “OK”. You’re ready to start writing code. Type “YouTube” and hit the period key (“.”). If the APIs have been turned on correctly, you will be able to start writing code and calling functions available in the Data API or Analytics API. For instance, a short script that searches for videos about “dogs” and prints the video IDs to the Google Apps Script log would look like this:


For more information about this update to Google Apps Script, check out the post on their official blog. To learn more about how to integrate scheduled jobs, write to spreadsheets or any of the many things Google Apps Script can do, check out the tutorials at their home at developers.google.com/apps-script. If you’re the type that prefers to learn on the go, get started with your own copy of our sample code in your Google Drive. You will still need to enable the APIs, so don’t forget to go to “Resources > Advanced Google services” for the link to the Developer Console project to turn on the APIs.

If you have any questions, feel free to find us on StackOverflow under the youtube-api and google-apps-script tags. Happy coding!

- Ikai Lan
YouTube Developer Relations

Friday, December 13, 2013

3.. 2.. 1.. and you are LIVE!

Since the YouTube Live Streaming API is announced, we’ve seen great tools and apps that helped eligible channels to stream their content on YouTube. 


Now that the YouTube Live Streaming platform is open to all verified channels, your live streaming apps will have a wider audience than ever.

How to start integration with the YouTube Live API:



  • Documentation
    • The Getting Started guide explains basic concepts of YouTube Live Streaming and of the API itself.
    • The Life of a Broadcast guide walks you through the typical steps for creating and managing a live broadcast on YouTube.
    • The YouTube Live Streaming Guide identifies the encoder settings, bitrates, and resolutions that the YouTube Live Streaming platform supports.

  • Sample code and tools
    • Client libraries for many different programming languages can help you implement the YouTube Live Streaming API as well as many other Google APIs.
    • Don't write code from scratch! Our Java, PHP, and Python code samples will help you get started.
    • The APIs Explorer lets you try out sample calls before writing any code.

In addition, in this video, we talk about the philosophy we followed in building the API and also show some great demos from our partners to help stimulate your creativity.


Stay tuned here and subscribe to the YouTube for Developers channel to keep up on the latest.

-Satyajeet Salgar, Tim James, Ibrahim Ulukaya and the YouTube Live Streaming Team

Tuesday, October 29, 2013

Let your users discover live events and track their audience

YouTube Live streaming platform enables eligible channels to stream live content on YouTube.  

With the addition of live streaming content to the Data API, you can make it easier for users to find information about these live streaming events:
  • get search results indicating whether a video is an upcoming or active live broadcast
  • get both scheduled and actual values of start and end time of the broadcast
  • get concurrent viewer count of a broadcast
  • search for live content via eventType filter

How to start implementing new features

  • Sample code and tools
    • Client libraries for many different programming languages can help you implement the YouTube Live Streaming API as well as many other Google APIs.
    • Don't write code from scratch! Our Java, PHP, and Python code samples will help you get started.
    • The APIs Explorer lets you try out sample calls before writing any code.

Stay tuned here and subscribe to the YouTube for Developers channel to keep up on the latest.

Keep it live,
-Derek Tan, Ibrahim Ulukaya and the YouTube Live Streaming Team

Wednesday, October 2, 2013

Spice up your channel with the InVideo Programming API

If you’ve used InVideo Programming before, you know that it’s a powerful way to attract subscribers to your channel. By featuring a watermark or a hit video on all videos on your channel, you can showcase the best of what your channel has to offer. You can also add a link to your home on social networks with a custom message to drive two-way conversation with your viewers on multiple fronts.

“That’s awesome,” you might say. “I’m already using it via the YouTube.com website!” Well, great! But did you know these options are available via our v3 Data API? The API enables all kinds of interesting use cases. Some examples:

  • Update the message to tease your latest tweet. When users click on your link, they are taken to your Twitter page
  • Feature the most recent upload to any channel on YouTube
  • Run a channel about television? You can write a script to rotate the featured video depending on whether it is the afternoon or the evening, a weekday or a weekend! Or, rotate the featured video daily to drive more views, reshares and discussion of quality content that might not be as fresh
  • Build a widget on your website or mobile app that lets your subscribers vote for a video to be featured every week! The video doesn’t have to be a video from your channel - it can be any video on YouTube!

InVideo Programming options are set as part of the channels resource, passed as a parameter to youtube.channels.update() in the invideoPromotion field. For instance, to feature this recent “YouTube Developers Live” show featuring our team’s favorite moments, I would structure the invideoPromotion field in my API request’s payload body like this:

invideoPromotion": {
"items": [
 {
  "id": {
   "type": "video",
   "videoId": "lzaYch2mqlU"
  },
  "timing": {
   "type": "offsetFromStart",
   "offsetMs": "0",
   "durationMs": "15000"
  }
 }
]
}

Other options for the type field in the id object include website and recentUpload, which correspond to InVideo Programming featuring a link, or automatically updating InVideo Programming featuring the latest video in a channel. For more information, see the documentation describing the invideoPromotion object in the channels resource.



A video featuring a watermark (top right) and InVideo Programming (bottom left)

Chances are good, though, that you’re using one of our API client libraries, which will help translate these API requests and responses into programmatic objects that you can manipulate and pass around in your code.

InVideo Programming functionality is relatively new, so if you are using an API client for a language like Java or .NET, you will need to make sure your client libraries are up-to-date before you can take advantage of these new features. Our samples are sorted by programming language on our Github page.

You can also set a channel’s watermark using the Data API’s watermarks.set() method. Watermarks are images that appear in the upper right hand corner of your videos that will link viewers to your channel on web and in the YouTube mobile apps for Android and iOS. This is usefu

InVideo Programming lets you reinforce your channel’s brand and drive viewers to other videos or social channels. The API makes it easy for your team to integrate InVideo Programming into your tools and workflow to make them more dynamic and interesting. Integrating the API into your tools and workflow only help to make your InVideo Programming more dynamic.

Happy coding!

Thursday, September 12, 2013

What to watch? Our APIs can help!

It’s an age-old question: what to watch? Applications that integrate with YouTube have access to countless hours of videos, and, as a developer, you have an interest in helping your users find the videos and channel most relevant to them. This blog post will walk you through a few ways that you can use the latest YouTube Data API to discover great content.

If you have an OAuth 2 token for the current user, your application can make a call to youtube.activities.list(part=”snippet”, home=true) to get back a list of videos and channels similar to the recommendations that the user would see on the YouTube.com home page. These results are customized for each individual user, and the list is kept fresh automatically, so it’s a great way to present your users with content they’re likely to enjoy.

Even if your users are not logged in, there are still are a few charts and guides at your disposal to aid in discovery.

To find popular videos your users might want to watch, youtube.videos.list(part=”snippet”, chart=”mostPopular”) is the basic API call to use. By default, it will return a list of videos in any category that are considered popular globally. If this is too broad a list, though, you can narrow things down using the regionCode or videoCategoryId (or both) parameters. regionCode can be set to a two-letter country code to retrieve a list of videos popular in that specific country (though not every country is currently supported). videoCategoryId needs to be set to an ID corresponding to one of our existing video categories—you can retrieve a list of valid categories and their corresponding IDs via youtube.videoCategories.list(part=”snippet”, regionCode=”XX”), where “XX” is also a two-letter country code.

There’s an analogous set of API calls that you could make to find channels your users might be interested in. youtube.guideCategories.list(part=”snippet”, regionCode=”XX”) will return a list of all the channel categories that are available in a given country. Once a user has chosen a category, you can get back a list of the most relevant channels in that category via a call to youtube.channels.list(part=”snippet”, categoryId=”CATEGORY_ID”), where “CATEGORY_ID” is the ID of the guide category you’re interested in. At that point, you could display a list of the most recent videos associated with each channel, and give your users the option of subscribing (assuming they grant OAuth 2 authorization first).

All of these examples assume that you’re using the latest version of the YouTube Data API, v3. Developers still using the Data API v1 or v2 should be aware of some recent changes to our older content discovery mechanism, standard feeds. As explained in the documentation, all of the previous different types of standard feeds are now returning the equivalent of the most_popular feed, with the time parameter set to “today”. If you are still using v1 or v2, there’s no time like the present (time=”today”, if you will) to make the switch to v3.

Update: For a walkthrough and demos of all the API calls, please watch this episode of YouTube Developers Live:



Cheers,