Servicio Content ID de YouTube

El servicio de Content ID de YouTube te permite usar la API de Content ID de YouTube en Apps Script. Esta API permite que los desarrolladores interactúen directamente con el sistema de administración de derechos de Content ID de YouTube. Como socio de YouTube, puedes usar la API para crear y administrar tus activos, reclamos y campañas.

Reference

Para obtener información detallada sobre este servicio, consulta la documentación de referencia de la API pública de Content ID de YouTube. Al igual que todos los servicios avanzados de Apps Script, el servicio avanzado de Content ID de YouTube usa los mismos objetos, métodos y parámetros que la API pública. Para obtener más información, consulta Cómo se determinan las firmas de métodos.

Para informar problemas y obtener ayuda adicional, consulta la guía de ayuda de la API de YouTube.

Código de muestra

El siguiente código de muestra utiliza la versión 1 de la API de Content ID de YouTube.

Reclamar tu video

Esta función crea un reclamo subido por un socio en tu video con las reglas de activos y políticas especificadas.

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

Actualización de la propiedad de los elementos

Esta función actualiza la propiedad de un activo existente.

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

Cómo retirar un reclamo

Esta función libera un reclamo existente sobre un 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);
  }
}