How can we add Youttube video assets to google performance ads?

413 views
Skip to first unread message

Binu Mathew

unread,
May 8, 2023, 4:49:05 AM5/8/23
to Google Ads API and AdWords API Forum
I am trying to add youtube video to assets of a google performance ads using following php code

   $i = 1;
             foreach ($youtubeURLs as $youtubeURL) {
            
                $operations = array_merge($operations, self::createYoutubeVideoAsset(
                    $customerId,
                    $youtubeURL,
                    AssetFieldType::YOUTUBE_VIDEO,
                    'Youtube URL' . $i
                ));
               
            }
 private static function createYoutubeVideoAsset (
        int $customerId,
        string $videoId,
         int $fieldType,
        string $assetName
    )
{
$operations[] = new MutateOperation([
            'asset_operation' => new AssetOperation([
                'create' => new Asset([
                    'resource_name' => ResourceNames::forAsset($customerId, self::$nextTempId),
                    'name' => $assetName,
                    'youtube_video_asset' => new YoutubeVideoAsset(['youtube_video_id' => $videoId]),
                ]),
            ]),
        ]);
 self::$nextTempId--;

        return $operations;
}

Can you give me a code sample ?


But its not adding.. Any idea whats went wrong? the video is adding to the campaign but not linking with the campaign, when i check the video is in the asset folder

Google Ads API Forum Advisor

unread,
May 8, 2023, 9:46:44 AM5/8/23
to binumat...@gmail.com, adwor...@googlegroups.com

Hello Binu,

Welcome to Google Ads API Support team. Thank you for reaching out to us.

We do have sample code for creating assets here (https://developers.google.com/google-ads/api/docs/assets/working-with-assets#create_an_asset). But instead of creating image asset you can replace that with youtube_video_asset (https://developers.google.com/google-ads/api/reference/rpc/v13/YoutubeVideoAsset) as shown here in asset data (https://developers.google.com/google-ads/api/reference/rpc/v13/Asset#asset_data).

Let us know should you have further questions.

Regards,

Google Logo Google Ads API Team


ref:_00D1U1174p._5004Q2lBOTJ:ref

Binu Mathew

unread,
May 8, 2023, 10:45:04 AM5/8/23
to Google Ads API Forum Advisor, adwor...@googlegroups.com
Thank you for your response.

Do you have a code sample to share with me?

Google Ads API Forum Advisor

unread,
May 9, 2023, 1:42:44 AM5/9/23
to binumat...@gmail.com, adwor...@googlegroups.com

Hi Binu,

Thank you for getting back to us.

We have already shared a sample code for creating assets in our previous response. However, allow me to share the link again specifying php code here (https://developers.google.com/google-ads/api/docs/assets/working-with-assets#php). As mentioned, instead of creating image asset, you can replace that with youtube_video_asset (https://developers.google.com/google-ads/api/reference/rpc/v13/YoutubeVideoAsset) as shown here in asset data (https://developers.google.com/google-ads/api/reference/rpc/v13/Asset#asset_data).

Please let us know how it goes on your end.

Reply all
Reply to author
Forward
0 new messages