บริการ Content ID ของ YouTube

จัดการเนื้อหา การอ้างสิทธิ์ และแคมเปญสำหรับพาร์ทเนอร์เนื้อหา YouTube

บริการ Content ID ของ YouTube ช่วยให้คุณใช้ API สำหรับ Content ID ของ YouTube ใน Google Apps Script ได้ API นี้ช่วยให้นักพัฒนาซอฟต์แวร์โต้ตอบกับระบบการจัดการสิทธิ์ของ Content ID ของ YouTube ได้โดยตรง ในฐานะพาร์ทเนอร์ YouTube คุณสามารถใช้ API เพื่อสร้างและจัดการ ชิ้นงาน การอ้างสิทธิ์ และแคมเปญได้

นี่เป็นบริการขั้นสูงที่ต้องเปิดใช้ก่อนใช้งาน

ข้อมูลอ้างอิง

ดูข้อมูลโดยละเอียดเกี่ยวกับบริการนี้ได้ที่เอกสารประกอบอ้างอิงสำหรับ Content ID API ของ YouTube สาธารณะ เช่นเดียวกับบริการขั้นสูงทั้งหมดใน Apps Script บริการ Content ID ของ YouTube ขั้นสูงจะใช้ออบเจ็กต์ เมธอด และ พารามิเตอร์เดียวกันกับ API สาธารณะ ดูข้อมูลเพิ่มเติมได้ที่ วิธีกำหนดลายเซ็นของเมธอด

หากต้องการรายงานปัญหาและรับการสนับสนุนอื่นๆ โปรดดูคู่มือการสนับสนุน YouTube API

โค้ดตัวอย่าง

โค้ดตัวอย่างต่อไปนี้ใช้ API สำหรับ Content ID ของ YouTube เวอร์ชัน 1

อ้างสิทธิ์ในวิดีโอ

ฟังก์ชันนี้จะสร้างการอ้างสิทธิ์ที่อัปโหลดโดยพาร์ทเนอร์ในวิดีโอของคุณตามกฎของเนื้อหาและนโยบายที่ระบุ

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,
    );
  }
}

อัปเดตการเป็นเจ้าของเนื้อหา

ฟังก์ชันนี้จะอัปเดตการเป็นเจ้าของเนื้อหาที่มีอยู่

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,
    );
  }
}

ถอนการอ้างสิทธิ์

ฟังก์ชันนี้จะยกเลิกการอ้างสิทธิ์ที่มีอยู่ซึ่งคุณมีในวิดีโอ

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);
  }
}