Dịch vụ Content ID của YouTube

Dịch vụ Content ID của YouTube cho phép bạn sử dụng API Content ID của YouTube trong Apps Script. API này cho phép nhà phát triển tương tác trực tiếp với hệ thống quản lý quyền qua Content ID của YouTube. Là đối tác của YouTube, bạn có thể sử dụng API này để tạo và quản lý tài sản, thông báo xác nhận quyền sở hữu và chiến dịch.

Tài liệu tham khảo

Để biết thông tin chi tiết về dịch vụ này, hãy xem tài liệu tham khảo về API Content ID công khai của YouTube. Giống như tất cả các dịch vụ nâng cao trong Apps Script, dịch vụ Content ID của YouTube nâng cao sử dụng cùng đối tượng, phương thức và tham số như API công khai. Để biết thêm thông tin, hãy xem phần Cách xác định chữ ký phương thức.

Để báo cáo vấn đề và tìm nguồn hỗ trợ khác, hãy xem Hướng dẫn hỗ trợ về API YouTube.

Mã mẫu

Mã mẫu bên dưới sử dụng phiên bản 1 của API Content ID YouTube.

Xác nhận quyền sở hữu video của bạn

Hàm này tạo thông báo xác nhận quyền sở hữu nội dung do đối tác tải lên đối với video của bạn bằng các quy tắc về chính sách và tài sản đã chỉ định.

advanced/youtubeContentId.gs
/**
 * This function creates a partner-uploaded claim on a video with the specified
 * asset and policy rules.
 * @see https://developers.google.com/youtube/partner/docs/v1/claims/insert
 */
function claimYourVideoWithMonetizePolicy() {
  // The ID of the content owner that you are acting on behalf of.
  const onBehalfOfContentOwner = 'replaceWithYourContentOwnerID';
  // A YouTube video ID to claim. In this example, the video must be uploaded
  // to one of your onBehalfOfContentOwner's linked channels.
  const videoId = 'replaceWithYourVideoID';
  const assetId = 'replaceWithYourAssetID';
  const claimToInsert = {
    'videoId': videoId,
    'assetId': assetId,
    'contentType': 'audiovisual',
    // Set the claim policy to monetize. You can also specify a policy ID here
    // instead of policy rules.
    // For details, please refer to the YouTube Content ID API Policies
    // documentation:
    // https://developers.google.com/youtube/partner/docs/v1/policies
    'policy': {'rules': [{'action': 'monetize'}]}
  };
  try {
    const claimInserted = YouTubeContentId.Claims.insert(claimToInsert,
        {'onBehalfOfContentOwner': onBehalfOfContentOwner});
    console.log('Claim created on video %s: %s', videoId, claimInserted);
  } catch (e) {
    console.log('Failed to create claim on video %s, error: %s',
        videoId, e.message);
  }
}

Cập nhật quyền sở hữu

Hàm này cập nhật quyền sở hữu của bạn đối với một tài sản hiện có.

advanced/youtubeContentId.gs
/**
 * This function updates your onBehalfOfContentOwner's ownership on an existing
 * asset.
 * @see https://developers.google.com/youtube/partner/docs/v1/ownership/update
 */
function updateAssetOwnership() {
  // The ID of the content owner that you are acting on behalf of.
  const onBehalfOfContentOwner = 'replaceWithYourContentOwnerID';
  // Replace values with your asset id
  const assetId = 'replaceWithYourAssetID';
  // The new ownership here would replace your existing ownership on the asset.
  const myAssetOwnership = {
    'general': [
      {
        'ratio': 100,
        'owner': onBehalfOfContentOwner,
        'type': 'include',
        'territories': [
          'US',
          'CA'
        ]
      }
    ]
  };
  try {
    const updatedOwnership = YouTubeContentId.Ownership.update(myAssetOwnership,
        assetId, {'onBehalfOfContentOwner': onBehalfOfContentOwner});
    console.log('Ownership updated on asset %s: %s', assetId, updatedOwnership);
  } catch (e) {
    console.log('Ownership update failed on asset %s, error: %s',
        assetId, e.message);
  }
}

Huỷ bỏ thông báo xác nhận quyền sở hữu

Chức năng này hủy bỏ thông báo xác nhận quyền sở hữu hiện có của bạn đối với một video.

advanced/youtubeContentId.gs
/**
 * This function releases an existing claim your onBehalfOfContentOwner has
 * on a video.
 * @see https://developers.google.com/youtube/partner/docs/v1/claims/patch
 */
function releaseClaim() {
  // The ID of the content owner that you are acting on behalf of.
  const onBehalfOfContentOwner = 'replaceWithYourContentOwnerID';
  // The ID of the claim to be released.
  const claimId = 'replaceWithYourClaimID';
  // To release the claim, change the resource's status to inactive.
  const claimToBeReleased = {
    'status': 'inactive'
  };
  try {
    const claimReleased = YouTubeContentId.Claims.patch(claimToBeReleased,
        claimId, {'onBehalfOfContentOwner': onBehalfOfContentOwner});
    console.log('Claim %s was released: %s', claimId, claimReleased);
  } catch (e) {
    console.log('Failed to release claim %s, error: %s', claimId, e.message);
  }
}