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

后端 未结 2 759
你的背包
你的背包 2020-12-10 04:47

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 enable

相关标签:
2条回答
  • 2020-12-10 05:05

    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
    0 讨论(0)
  • 2020-12-10 05:20

    Seems like currently the Data API doesn't respect channel default settings when uploading new videos, nevertheless you can enable monetization (claim ownership) using the Content ID API. See this example

    https://developers.google.com/youtube/partner/upload_claim_sample

    0 讨论(0)
提交回复
热议问题