googleads / google-ads-php

Google Ads API Client Library for PHP
https://developers.google.com/google-ads/api/docs/client-libs/php
Apache License 2.0
294 stars 262 forks source link

DiscoveryCarouselAdInfo -> AdDiscoveryCarouselCardAsset -> ?? Asset #859

Closed lambertbeekhuis closed 1 year ago

lambertbeekhuis commented 1 year ago

Hello,

I am using V12, and run in something I probably understand wrong.

I try to make a DiscoveryCampaign with the DiscoveryCarouselAdInfo This contains the AdDiscoveryCarouselCardAsset Which refers to a normal Asset???? - I would think it would require a DiscoveryCarouselCardAsset instead of a normal Asset.

And if I want to make a resource of DiscoveryCarouselCardAsset, I am missing the Service for this and the ServiceClient, so cannot make e resource of it, as I miss the services for this.

Probably I make a mistake, or is there something with the library? (missing services?)

Below code and response I am using

$image_square = "customers/3589352691/assets/64302704760";
$image_191 = "customers/3589352691/assets/64255230644";
$image_45 = "customers/3589352691/assets/64242061498";

 // tried this, but could no 'upload' it via an asset operation as I miss a service for it. 
        $cardResource1 = self::createDiscoveryCarouselCardAsset($googleAdsClient, $customerId, $adGroupResourceName,
           $image_square, null, $image_45, "Title", "Description", "https://www.example.com");

        $cardResource2 = self::createDiscoveryCarouselCardAsset($googleAdsClient, $customerId, $adGroupResourceName,
            null, $image_191, $image_45, "Title", "Description", "https://www.example.com");

// ??? this works, but should refer to DiscoveryCarouselCardAsset I would think...????
        $card1 = new AdDiscoveryCarouselCardAsset(['asset' => $image_square]);
        $card2 = new AdDiscoveryCarouselCardAsset(['asset' => $image_191]);

        // https://developers.google.com/google-ads/api/reference/rpc/v12/DiscoveryCarouselAdInfo
        $discoveryAd = new DiscoveryCarouselAdInfo();
        $discoveryAd->setBusinessName('business name');
        $discoveryAd->setHeadline(new AdTextAsset(['text' => 'headline']));
        $discoveryAd->setLogoImage(new AdImageAsset(['asset' => $image_square]));
        $discoveryAd->setDescription(new AdTextAsset(['text' => 'descriptiron']));

            $discoveryAd->setCarouselCards([
                new AdDiscoveryCarouselCardAsset(['asset' => $image_square]),
     // ????  or card1 or $cardResource1? but these are not uploaded/have no resource name
                new AdDiscoveryCarouselCardAsset(['asset' => $image_191]), // or card2? $cardResource2?
            ]) // needs the resources
        ;

        $ad = (new Ad([
                'discovery_carousel_ad' => $discoveryAd,
            ]))
            ->setFinalUrls(['https://www.example.com'])
        ;

        // Creates a new ad group ad.
        $adGroupAd = new AdGroupAd([
            'ad' => $ad,
            'ad_group' => $adGroupResourceName
        ]);

        // Creates an ad group ad operation.
        $adGroupAdOperation = new AdGroupAdOperation();
        $adGroupAdOperation->setCreate($adGroupAd);

        // Issues a mutate request to add the ad group ad.
        $adGroupAdServiceClient = $googleAdsClient->getAdGroupAdServiceClient();
        $response = $adGroupAdServiceClient->mutateAdGroupAds($customerId, [$adGroupAdOperation]);

I get the response

{
    "message": "Request contains an invalid argument.",
    "code": 3,
    "status": "INVALID_ARGUMENT",
    "details": [
        {
            "@type": "type.googleapis.com\/google.ads.googleads.v12.errors.GoogleAdsFailure",
            "errors": [
                {
                    "errorCode": {
                        "assetLinkError": "FIELD_TYPE_INCOMPATIBLE_WITH_ASSET_TYPE"
                    },
                    "message": "The given asset's type and the specified field type are incompatible.",
                    "trigger": {
                        "int64Value": "64302704760"
                    },
                    "location": {
                        "fieldPathElements": [
                            {
                                "fieldName": "operations",
                                "index": 0
                            },
                            {
                                "fieldName": "create"
                            },
                            {
                                "fieldName": "ad"
                            },
                            {
                                "fieldName": "discovery_carousel_ad"
                            },
                            {
                                "fieldName": "carousel_cards",
                                "index": 0
                            },
                            {
                                "fieldName": "asset"
                            }
                        ]
                    }
                },
                {
                    "errorCode": {
                        "assetLinkError": "FIELD_TYPE_INCOMPATIBLE_WITH_ASSET_TYPE"
                    },
                    "message": "The given asset's type and the specified field type are incompatible.",
                    "trigger": {
                        "int64Value": "64255230644"
                    },
                    "location": {
                        "fieldPathElements": [
                            {
                                "fieldName": "operations",
                                "index": 0
                            },
                            {
                                "fieldName": "create"
                            },
                            {
                                "fieldName": "ad"
                            },
                            {
                                "fieldName": "discovery_carousel_ad"
                            },
                            {
                                "fieldName": "carousel_cards",
                                "index": 1
                            },
                            {
                                "fieldName": "asset"
                            }
                        ]
                    }
                }
            ],
            "requestId": "C8RXexuR2vc2O5RpoVIOmw"
        }
    ]
}
fiboknacky commented 1 year ago

The structure should be like this:

Ad -> DiscoveryCarouselAdInfo -> AdDiscoveryCarouselCardAsset -> Asset -> DiscoveryCarouselCardAsset

You cannot store the DiscoveryCarouselCardAsset object directly under AdDiscoveryCarouselCardAsset. You need to first create an Asset and an DiscoveryCarouselCardAsset. Then, set the DiscoveryCarouselCardAsset to the discovery_carousel_card_asset field.

lambertbeekhuis commented 1 year ago

Ok, thanks. And what service do I need to upload/mutate the DiscoveryCarouselCardAsset?

An asset is stored like ` // Creates an asset operation. $assetOperation = new AssetOperation(); $assetOperation->setCreate($asset);

    // Issues a mutate request to add the asset.
    $assetServiceClient = $googleAdsClient->getAssetServiceClient();
    $response = $assetServiceClient->mutateAssets(
        $customerId,
        [$assetOperation]
    );

` How is the DiscoveryCarouselCardAsset stored?

fiboknacky commented 1 year ago

You need to set the newly created DiscoveryCarouselCardAsset object to the discovery_carousel_card_asset field of Asset.

So, when you use the AssetServiceClient to create Asset, DiscoveryCarouselCardAsset will be created together.

lambertbeekhuis commented 1 year ago

Thanks so much, been searching a whole that for it. That was the link the one I was missing!!

fiboknacky commented 1 year ago

Sure. Let us know if you need any help in the future. :)