2017-06-08 25 views
0

PHPのGoogleクライアントライブラリを使用してYouTubeに動画をアップロードするアプリケーションを構築しています。動画をアップロードできましたが、[収益受け取り]チェックボックスを切り替えられませんでした。ウェブに関する情報はほとんどありません。APIを使用して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)); 

答えて

1

あなたのために働いていない場合は、このコード

$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の動画IDた後、ビデオをアップロードした後、ここにすべてのコードを置きます。 $ videoIdと$ contentOwnerIdを変更するだけです

+0

こんにちはJulian、ありがとうございました。しかし、私はまだ苦労しています。あなたは最後のパラグラフの答えを詳しく教えていただけますか?私は何かに入っているようですが、現在は非常に不明です。ありがとうございます – floCoder

0

上記のコードは、収益受け取りにのみ対応する部分です。動画をYouTubeにアップロードしておく必要があります。あなたがvideoとcontentOwnerIdのIDを持っていれば、コードは何も変えずに動作するはずです。コードのこの部分のみを試してみて、それがあなたのために動作しない場合は、成功した場合は、次の要求

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

に私にtoutubeの答えを得る、この方法は、レスポンスボディに請求リソースを返します。それ以外の場合はエラーを返します。エラーが返された場合は、エラーを出してください。何が起きているかを教えてください。

+0

こんにちはジュリアンはあなたの助けに感謝します。はい、動画をアップロードしてIDを取得できましたが、コンテンツ所有者IDを取得できませんでした。私はちょっと調べて、私が私とは思っていないYouTubeのパートナーになる必要があることを知りました。コンテンツ所有者IDがないということですか?コンテンツオーナーのIDなしでお金を稼ぐことはできますか?もしあなたがここにいくつかのコードを置くことができますか?ありがとうございます – floCoder

+0

あなたがyoutubeパートナーでない場合、yopはcontentIdで動画で収益を上げることはできません。 YouTubeのウェブインターフェイスでのみ。 – Julian

関連する問題