googleads / googleads-php-lib

Google Ad Manager SOAP API Client Library for PHP
Apache License 2.0
656 stars 769 forks source link

Example Code: cvc-type.2: The type definition cannot be abstract for element ns1:creatives #772

Closed illusive-ch closed 1 year ago

illusive-ch commented 1 year ago

I have the following code

       $creativeService = $this->serviceFactory->createCreativeService($this->session);

        $imageCreative = new ImageCreative();
        $imageCreative->setName('Image creative #'.uniqid());
        $imageCreative->setAdvertiserId($creative->campaign->team->provider_id);
        $imageCreative->setDestinationUrl('http://google.com');

        // Set the size of the image creative.
        $size = new Size();
        $size->setWidth(600);
        $size->setHeight(315);
        $size->setIsAspectRatio(false);
        $imageCreative->setSize($size);

        // Set the creative's asset.
        $creativeAsset = new CreativeAsset();
        $creativeAsset->setFileName(300);
        $creativeAsset->setAssetByteArray(
            base64_encode(file_get_contents('https://placehold.co/300x250/jpg'))
        );
        $imageCreative->setPrimaryImageAsset($creativeAsset);

        // Create the image creatives on the server.
        $results = $creativeService->createCreatives([$imageCreative]);

        // Print out some information for each created image creative.
        foreach ($results as $i => $imageCreative) {
            printf(
                "%d) Image creative with ID %d and name '%s' was created.%s",
                $i,
                $imageCreative->getId(),
                $imageCreative->getName(),
                PHP_EOL
            );
        }

This pretty much mirrors the example code other then the image being different since the image int he example is 404 https://github.com/googleads/googleads-php-lib/blob/main/examples/AdManager/v202211/CreativeService/CreateCreatives.php

From what I can see this is the soap call :

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <soap:Fault>
            <faultcode>soap:Client</faultcode>
            <faultstring>Unmarshalling Error: cvc-type.2: The type definition cannot be abstract for element
                ns1:creatives.
            </faultstring>
        </soap:Fault>
    </soap:Body>
</soap:Envelope>

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:ns1="https://www.google.com/apis/ads/publisher/v202211">
<SOAP-ENV:Header>
    <ns1:RequestHeader>
        <ns1:networkCode>xxxx</ns1:networkCode>
        <ns1:applicationName>xxxxx (DfpApi-PHP, googleads-php-lib/59.0.0, PHP/8.1.14)</ns1:applicationName>
    </ns1:RequestHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
    <ns1:createCreatives>
        <ns1:creatives>
            <ns1:advertiserId>xxxx</ns1:advertiserId>
            <ns1:name>Image creative #63c54fdb46445</ns1:name>
            <ns1:size>
                <ns1:width>300</ns1:width>
                <ns1:height>250</ns1:height>
                <ns1:isAspectRatio>false</ns1:isAspectRatio>
            </ns1:size>
        </ns1:creatives>
    </ns1:createCreatives>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I have also tried with and without base64 the image on file_get_contents()

PierrickVoulet commented 1 year ago

Hi @illusive-ch - You should not need to use base64 (file_get_contents should return the content as a byte array as expected). If you remove the base64 call, are you getting the exact same error? Could you provide us with the complete logs?

PierrickVoulet commented 1 year ago

Closing due to inactivity.