Use OAuth 2.0 for Service Accounts

Note: The YouTube Content ID API is intended for use by YouTube content partners and is not accessible to all developers or to all YouTube users. If you do not see the YouTube Content ID API as one of the services listed in the Google API Console, see the YouTube Help Center to learn more about the YouTube Partner Program.

Background

A service account is a Google Account that can be used to authorize API calls without any user interaction. Unlike the other OAuth 2.0 flows, authenticating and authorizing access using the OAuth 2.0 for service accounts flow does not take place in a web browser. Instead, OAuth 2.0 for service accounts relies on cryptographic signatures to authorize access. As long as your code has access to the underlying cryptographic key, it can continue making API calls without worrying about refresh and access tokens. It's perfect for automated applications running on servers without human intervention.

You can now use the OAuth 2.0 for service accounts flow to authorize YouTube Content ID API requests. You can also use this flow to authorize YouTube Data API and YouTube Analytics API calls to methods that support delegation parameters. In all of these cases, an application using this flow is authorizing the API request as a YouTube Content Partner (using a YouTube CMS account) rather than as a YouTube channel owner.

Set up your service account

The following screenshots illustrate the process of creating a service account associated with your API Project, which you should ensure already has the appropriate APIs (YouTube Data API v3, YouTube Analytics API, YouTube Content ID API, etc.) enabled.

  1. Visit https://cloud.google.com/console and choose your existing API Project (or create a new one).
  2. In the sidebar on the left, select APIs & auth.
  3. Make sure the YouTube Content ID API is activated for your project.
  4. In the sidebar on the left, select Credentials.
  5. Click the Create new client ID button.
  6. Choose Service account from the listed options and click Create client ID. The private key for your service account will be downloaded to your machine. This is the only copy of the key and you need to save the key in a secure location that your application can read from.
  7. Make note of the email address for the service account. (The email address appears on the Credentials page.) You will need the address to grant your service account the ability to access your YouTube CMS account.
  8. Visit https://www.youtube.com/content_owner_users and click the New user button.
  9. Enter the email address of the service account from step 7 in the Email address field and choose the appropriate role for the user. Then click the Invite button.
  10. Your service account automatically accepts the invitation, and that account can subsequently access the YouTube APIs acting on behalf of your YouTube CMS account.
  11. Follow the instructions for the OAuth 2.0 service account flow in the authorizing requests guide to authorize requests using your service account.

Make API Calls

Most languages' client libraries have native support for the OAuth 2.0 for service account flow. You should be able to follow the examples in the library's documentation to perform basic authorization with the appropriate YouTube API scopes.

The most important thing to keep in mind is that you must use the appropriate delegation parameters to act on behalf of a given channel linked to your CMS account. To view a list of channels linked to your CMS account, visit https://cms.youtube.com/edit_user_accounts.