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