Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable monetization for videos uploaded with YouTube Data API v3?

I have a verified partner channel on YouTube, and I'm trying to enable monetization for videos uploaded via the YouTube Data API (v3).

The channel is already enabled for monetization, and I've enabled monetization in Channel Settings → Defaults (although I have a feeling that this page is only for setting the defaults on the standard manual upload page). I've looked in the API reference, but can't find anything related to monetization at all.

Is there some other way to automatically make new videos uploaded by any means monetized, or some way I can enable it in the API?

like image 311
Robert Avatar asked Sep 14 '13 10:09

Robert


1 Answers

The link that Tareq supplied is correct, but unfortunately it only shows some python code instead of what is going on using HTTP. Since I wanted to do the same, here is what I have figured out and what works for me. Note again that you need access to the ContentID API (vote for this ticket to get this fixed) which means you need to have access to a owners of an CMS Account. Confusingly there exists a YouTube Partner Program which has nothing to do with being a "YouTube Partner". You need access to a CMS account which is e.g. the case if you are running an multi channel network (MCN). Additionally I get the impression that the documentation is actually quite well hidden because even if I know exactly what I am looking for I always have a hard time to find the documentation pages again.

Anyway: Here is the stuff:

1. Create asset

First you need to create an asset (docs):

POST https://www.googleapis.com/youtube/partner/v1/assets?onBehalfOfContentOwner=CONTENT_OWNER_ID
Authorization: Bearer ...

{
  "type": "web",
  "metadata": {
    "title": "some title, typically the same as the video title",
    "customId": "optional, but typically the same as the videoId"
  }
}

In the response body you'll find:

{
  ...
  "id": "ASSET_ID"
  ...
}

Save the ASSET_ID for later.

2. Set ownership

Now we tell YouTube that we exclusively own everything connected with the asset to 100% exclusively and worldwide (docs):

PUT https://www.googleapis.com/youtube/partner/v1/assets/ASSET_ID/ownership?onBehalfOfContentOwner=CONTENT_OWNER_ID
Authorization: Bearer ...

{
  "general": {
    "owner": "CONTENT_OWNER_ID",
    "ratio": 100,
    "type": "exclude"
  }
}

Note that this is a PUT request and not a POST!

3. Claim the video with a monetization policy

Now we connect the video, the asset and a policy whith each other (docs)

POST https://www.googleapis.com/youtube/partner/v1/claims?onBehalfOfContentOwner=CONTENT_OWNER_ID
Authorization: Bearer ...

{
  "assetId": "ASSET_ID",
  "videoId": "VIDEO_ID",
  "policy": {
    "id": "POLICY_ID"
  },
  "contentType": "audiovisual"
}

Now your video should will be monetized according to some policy.

What you need to know

In my examples you will of course need to replace the variables I left in there in capital letters:

  • CONTENT_OWNER_ID: Find out your id using and authenticated call to GET https://www.googleapis.com/youtube/partner/v1/contentOwners?fetchMine=true (docs)
  • ASSET_ID: It is returned in the responseBody of the create asset call
  • POLICY_ID: Find out what policies with which ids you have with an authenticated call to GET https://www.googleapis.com/youtube/partner/v1/policies?onBehalfOfContentOwner=CONTENT_OWNER_ID (docs)

For all the request you need to be authenticated with the scope https://www.googleapis.com/auth/youtubepartner

This is just one way and option set of applying monetizations. The API endpoints that I showed have more and different options. Refer to the docs.

See also

  • Vote for this ticket so that default monetization policies are also applied for videos uploaded through the API.
  • Vote for this ticket so that we get the ability to specify monetization settings during upload without the need to have access to a CMS account
like image 135
yankee Avatar answered Sep 19 '22 12:09

yankee