Issue uploading Image Ads

87 views
Skip to first unread message

RS

unread,
Nov 24, 2021, 9:16:24 AM11/24/21
to AdWords API and Google Ads API Forum
Hi,

I'm trying to create an Image Ad inside an ad group. Here is my code (php):

        $adGroupAd = new AdGroupAd([
           'ad' => new Ad([
               'name' => $name,
               'final_urls' => $urls,
               'image_ad' => new ImageAdInfo([
                   'mime_type' => MimeType::IMAGE_PNG,
                   'pixel_width' => 200,
                   'pixel_height' => 200,
                   'image_url' => $pngImageUrl,
                   'preview_pixel_width' => 200,
                   'preview_pixel_height' => 200,
                   'preview_image_url' => $pngImageUrl,
                   'name' => $imageName,
                   'data' => file_get_contents($pngImageUrl),
               ])
           ]),
           'ad_group' => ResourceNames::forAdGroup($this->customerId, $adGroupId),
           'status' => AdGroupAdStatus::PAUSED
       ]);

I've attached the error as a separate file.

It seems to have to do with the 'data' attribute in the ImageAdInfo class, the error being adError: EMPTY_FIELD on the data attribute, reading: 'A required field was not specified or is an empty string.'.

I'm passing binary data (using file_get_contents()) as explained can be done here:

But does not work. Any clue?

Thanks,
R

error.PNG

Google Ads API Forum Advisor

unread,
Nov 24, 2021, 10:02:08 PM11/24/21
to rasmus....@gmail.com, adwor...@googlegroups.com
Hi R,

Thank you for reaching out to our API support team.

As per the data attribute documentation, the information to be passed should be "Raw image data as bytes.". That said, and as we are not familiar with all the available methods from the client libraries, could you provide more details on what the file_get_contents() outputs?

Also, so our team can take a closer look at the cause, could you provide as well the complete request and response logs, with the request-id, generated when the error occurred? 

If you haven't yet, you can enable logging by referring to this PHP client library guide. You may then send the requested information via the Reply privately to author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.

Best regards,

Reminder: Share your feedback about the Google Ads (AdWords) API! Take the 2021 Google Ads API and AdWords API Annual Survey
 
Google Logo
Peter Laurence Napa Oliquino
Google Ads API Team
 


ref:_00D1U1174p._5004Q2RvvI1:ref

RS

unread,
Nov 29, 2021, 4:45:12 AM11/29/21
to AdWords API and Google Ads API Forum
Hi,

Thanks for the followup,

So once again I want to create and upload a completely new image ad inside an existing ad group/campaign using an image url.

So I will post the error logs in two sections below.

So the first log, is when I use the 'data' attribute as below:

        $ adGroupAd = new AdGroupAd ([
           'ad' => new Ad ([
               'name' => $ name,
               'final_urls' => $ urls,
               'image_ad' => new ImageAdInfo ([
                   'mime_type' => MimeType :: IMAGE_PNG,
                   'pixel_width' => 200,
                   'pixel_height' => 200,
                   'image_url' => $pngImageUrl,
                   'preview_pixel_width' => 200,
                   'preview_pixel_height' => 200,
                   'preview_image_url' => $pngImageUrl,
                   'name' => $ imageName,
                   'data' => file_get_contents ($pngImageUrl),
               ])
           ]),
           'ad_group' => ResourceNames :: forAdGroup ($ this-> customerId, $ adGroupId),
           'status' => AdGroupAdStatus :: PAUSED
       ]);

The error log is then as follows:

[2021-11-26 15:15:20] laravel.ERROR: {
    "message": "Request contains an invalid argument.",
    "Code": 3,
    "status": "INVALID_ARGUMENT",
    "details": [
        {
            "@type": 0,
            "data": " type.googleapis.com // google. ads.googleads.v8.errors. GoogleAdsFailure"
        },
        {
            "@type": 0,
            "data": [
                {
                    "errorCode" : {
                        "adError": "EMPTY_FIELD"
                    },
                    "message": "A required field was not specified or is an empty string.",
                    "trigger": {
                        "stringValue": ""
                    },
                    "location": {
                        "fieldPathElements": [
                            {
                                "fieldName": "operations",
                                "index": 0
                            },
                            {
                                "fieldName": "create"
                            },
                            {
                                "fieldName": "ad"
                            },
                            {
                                "fieldName": "display_url"
                            }
                        ]
                    }
                }
            ]
        },
        {
            "@type": 0,
            "data": "dL89I3epo9eHKHelHqeSsQ"
        }
    ]
} {"userId": 505, "exception": "[ object] (Google \ \ ApiCore \\ ApiException (code: 3): {
    \ "message \": \ "Request contains an invalid argument. \",
    \ "Code \": 3,
    \ "status \": \ "INVALID_ARGUMENT \",
    \ "details \":[
        {
            \ "@ type \": 0,
            \ "data \": \ " type.googleapis.com\\ / google.ads.googleads.v8. errors.GoogleAdsFailure \ "
        },
        {
            \" @ type \ ": 0,
            \" data \ ": [
                {
                    \" errorCode \ ": {
                        \" adError \ ": \" EMPTY_FIELD \ "
                    },
                    \" message \ " : \ "A required field was not specified or is an empty string. \",
                    \ "Trigger \": {
                        \ "stringValue \": \ "\"
                    },
                    \ "location \": {
                        \ "fieldPathElements \":

                                \ "fieldName \": \ "operations \",
                                \ "index \": 0
                            },
                            {
                                \ "fieldName \": \ "create \"
                            },
                            {
                                \ "fieldName \": \ "ad \"
                            },
                            {
                                \ "fieldName \": \ "display_url \"
                            }
                        ]
                    }
                }
            ]
        },
        {
            \ "@ type \": 0,
            \ "data \": \ "dL89I3epo9eHKHelHqeSsQ \"
        }
    ]


_________________________________________________________________________

Comment: I notice the fieldname 'display_url'.
This does not seem to be included in the documentation for ImageAdInfo. Am I missing something here?
______________________________ ______________________________ ____________

Secondly, I tried the 'media_file' attribute instead of 'data' in the ImageAdInfo constructor as below:

                   'media_file' => new MediaFile ([
                       'source_url' => $pngImageUrl ,
                       'name' => 'testname' ,
                       'type' => MediaType :: IMAGE,
                   ]),

There was an issue retrieving the full log, but below is the end of the stack trace (modified some local paths):

[2021-11-26 15:23:28] laravel.ERROR: Expect string. {"userId": 505, "exception": "[ object] (InvalidArgumentException ( code: 0): Expect string. at localpath \\ google \\ protobuf \\ src \\ Google \\ Protobuf \\ Internal \\ GPBUtil. php: 96)
[stacktrace]
# 0 localpath \\ googleads \\ google- ads-php \\ src \\ Google \\ Ads \\ GoogleAds \\ V8 \\ Common \\ ImageAdInfo.php (411): Google \\ Protobuf \\ Internal \\ GPBUtil :: checkString (Object ( Google \\ Ads \\ GoogleAds \\ V8 \\ Resources \\ MediaFile), true)
# 1 localpath \\ google \\ protobuf \\ src \\ Google \\ Protobuf \\ Internal \\ Message .php (1081): Google \\ Ads \\ GoogleAds \\ V8 \\ Common \\ ImageAdInfo-> setMediaFile (Object (Google \\ Ads \\ GoogleAds \\ V8 \\ Resources \ \ MediaFile))
# 2 localpath \ \ google \\ protobuf \\ src \\ Google \\ Protobuf \\ Internal \\ Message.php (80): Google \\ Protobuf \\ Internal \\ Message-> mergeFromArray (Array)
# 3 localpath \\ googleads \\ google-ads-php \\ src \\ Google \\ Ads \\ GoogleAds \\ V8 \\ Common \\ ImageAdInfo.php (103): Google \\ Protobuf \\ Internal \\ Message -> __ construct (Array)
# 4 pathtodriver \ \ GoogleAdsDriver. php (x): Google \\ Ads \\ GoogleAds \\ V8 \\ Common \\ ImageAdInfo -> __ construct (Array)
# 5 pathtodriver \\ GoogleAdsDriver. php (x): pathtodriver \\ GoogleAdsDriver- > createImageAd ()

______________________________________________________

Note:
I notice a failure in this method in ImageAdInfo.php:

    public function setMediaFile($var)
    {
        GPBUtil::checkString($var, True);
        $this->writeOneof(12, $var);

        return $this;
    }

It fails here: GPBUtil::checkString($var, True);

I notice the $var passed in is the MediaFile object (not a string).
Why is it expecting a string?

Let me know if you have any more questions!

Kind regards,
R

Google Ads API Forum Advisor

unread,
Nov 30, 2021, 1:16:29 PM11/30/21
to rasmus....@gmail.com, adwor...@googlegroups.com
Hi there,

Could you set your logger loglevel to 'DEBUG' and send us the results?


Reminder: Share your feedback about the Google Ads (AdWords) API! Take the 2021 Google Ads API and AdWords API Annual Survey
 
Regards,
Google Logo
Aryeh Baker
Google Ads API Team
 

 

ref:_00D1U1174p._5004Q2RvvI1:ref

Google Ads API Forum Advisor

unread,
Nov 30, 2021, 1:17:51 PM11/30/21
to adwor...@googlegroups.com, rasmus....@gmail.com
Hi,


You may then send the requested information via the Reply privately to author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.

Reply all
Reply to author
Forward
0 new messages