gpt4 book ai didi

php - 如何使用API​​在YouTube上启用“通过广告获利”选项

转载 作者:行者123 更新时间:2023-12-03 05:55:17 27 4
gpt4 key购买 nike

我正在构建一个使用PHP Google Client Library将视频上传到YouTube的应用程序。我可以上传视频,但无法在“获利”复选框上切换。网络上的信息很少。

我发现此链接很有帮助。 http://www.techtonet.com/youtube-upload-videos-with-partner-api-in-php/#ipt_kb_toc_51_6

但是我无法做到这一点。

请帮忙。

// Create a claim resource. Identify the video being claimed, the asset
// that represents the claimed content, the type of content being claimed,
// and the policy that you want to apply to the claimed video.
$claim = new Google_Service_YouTubePartner_Claim();
$claim->setAssetId($assetId);
$claim->setVideoId($videoId);
$claim->setPolicy($policy);
$claim->setContentType("audiovisual");

// Insert the created claim.
$claimInsertResponse = $this->_youtubePartner->claims->insert($claim,
array('onBehalfOfContentOwner' => $contentOwnerId));

# Enable ads for the video. This example enables the TrueView ad format.
$option = new Google_Service_YouTubePartner_VideoAdvertisingOption();
//$option->setAdFormats(array("overlay", "trueview_instream", "standard_instream"));
$option->setAdFormats(array("trueview_instream", "standard_instream"));
$setAdvertisingResponse = $this->_youtubePartner->videoAdvertisingOptions->update(
$videoId, $option, array('onBehalfOfContentOwner' => $contentOwnerId));

最佳答案

对我来说,正在使用此代码

$youtubePartner = new \Google_Service_YouTubePartner($this->client);

$asset = new \Google_Service_YouTubePartner_Asset();
$metadata = new \Google_Service_YouTubePartner_Metadata();
$youtubePartner = new \Google_Service_YouTubePartner($this->client);
$metadata->setTitle("Asset Title"));
$metadata->setDescription("AssetDescription");
$asset->setMetadata($metadata);
$asset->setType("web");

$assetInsertResponse = $youtubePartner->assets->insert($asset, [
'onBehalfOfContentOwner' => $this->contentOwnerId
]);

$assetId = $assetInsertResponse['id'];

$ratio = 100;
$type = "exclude";
$territories = [];

$owners = new \Google_Service_YouTubePartner_TerritoryOwners();
$owners->setOwner($this->contentOwnerId);
$owners->setRatio($ratio);
$owners->setType($type);
$owners->setTerritories($territories);
$ownership = new \Google_Service_YouTubePartner_RightsOwnership();
$ownership->setGeneral([$owners]);
$youtubePartner->ownership->update($assetId, $ownership, ['onBehalfOfContentOwner' => $contentOwnerId]);

$policy = new \Google_Service_YouTubePartner_Policy();
$policyRule = new \Google_Service_YouTubePartner_PolicyRule();
$policyRule->setAction("monetize");
$policy->setRules(array($policyRule));

$claim = new \Google_Service_YouTubePartner_Claim();
$claim->setAssetId($assetId);
$claim->setVideoId($videoId);
$claim->setPolicy($policy);
$claim->setContentType("audiovisual");


$claimInsertResponse = $youtubePartner->claims->insert($claim, [
'onBehalfOfContentOwner' => $contentOwnerId,
]);

如果不适用于您,则在上传视频后,一旦您从YouTube获得了videoId,就将所有代码放在此处。
您只需要更改$ videoId和$ contentOwnerId

关于php - 如何使用API​​在YouTube上启用“通过广告获利”选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44427661/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com