calling getData() on an image always returns null in PHP library

51 views
Skip to first unread message

Joel Shapiro

unread,
Jun 14, 2017, 3:15:50 PM6/14/17
to AdWords API Forum
I'm trying to extract data from an existing ResponsiveDisplayAd and move it to another following the example in AddResponsiveDisplayAd.php and instead of calling:

$image->setData(file_get_contents('http://goo.gl/3b9Wfh'));


would like to call 

$image->setData($originalImage->getData());


The documentation here (https://developers.google.com/adwords/api/docs/reference/v201702/MediaService.Image) doesn't lead me to believe that I need to add anything to my selectors. These are what I'm selecting right now when I hit the AdGroupService:

$selector->setFields([
        'Id',
        'AdType',
        'BaseAdGroupId',
        'CreativeFinalUrls',
        'CreativeTrackingUrlTemplate',
        'Name',
        'Dimensions',
        'DisplayUrl',
        'MarketingImage',
        'LogoImage',
        'ShortHeadline',
        'LongHeadline',
        'Description',
        'BusinessName',
        'MediaId',
        'Urls'
]);


In the results I access the image via

foreach ($page->getEntries() as $adGroupAd) {
        $currAd = $adGroupAd->getAd();
        $marketingImage
= $currAd->getMarketingImage();

        $marketingImage->getData() === null // true
        $marketingImageURLs
= $marketingImage->getUrls();

        $marketingImageURLs[0]->getValue(); // string of image URL

}

I don't want to have to use file_get_contents with the image's URL like the example, getData() seems like it should be the way to do this. Any help is greatly appreciated.

Peter Oliquino

unread,
Jun 15, 2017, 2:07:54 AM6/15/17
to AdWords API Forum
Hi Joel, 

I'm afraid you cannot retrieve the raw image data of a Media using MediaService. If you would like to reuse existing Images to create new ResponsiveDisplayAds, you can populate the Image.mediaId field with the MediaId as shown here. You can use MediaService to retrieve the uploaded images as shown here.

Regards,
Peter
AdWords API Team

Joel Shapiro

unread,
Jun 15, 2017, 12:58:05 PM6/15/17
to AdWords API Forum
Thank you for the response, but is there a way that I could have known this? The documentation includes getData() but it sounds like you're saying that there's no way to use it. Can you explain how one would successfully use getData() on an image?

Peter Oliquino

unread,
Jun 16, 2017, 1:36:45 AM6/16/17
to AdWords API Forum
Hi Joel,

Could you confirm if this (Data) is the documentation that you are referring to? Currently, there is no mention that the said field can be selected, otherwise you will see something similar as seen in the Name field (This field can be selected using the value "Name"). I hope this has been helpful and please feel free to write back if you have any follow up questions.

Best regards,
Peter
AdWords API Team

Joel Shapiro

unread,
Jun 16, 2017, 12:57:49 PM6/16/17
to AdWords API Forum
Sorry, I mispoke, the Image class includes the getData() function, but you're saying that it cannot be used. Why is getData() included in the class? It seems as though it is inviting confusion to include class functions that appear to do something obvious but serve little purpose.

Maybe I'm the only one who expects a getData() function to return data, I don't know.

Thanet Knack Praneenararat (AdWords API Team)

unread,
Jun 19, 2017, 1:44:40 AM6/19/17
to AdWords API Forum
Hello Joel,

Classes in client libraries are generated automatically using WSDL, e.g., https://adwords.google.com/api/adwords/cm/v201705/AdGroupAdService?wsdl,
and the getter and setter are generated for each field by default.

Please consult this page to see what fields can be selected.
If a certain field isn't explicitly specified in the selector or it can't be selected at first (e.g., it can be used in mutate operation only, but not get), the getter of that field will return nothing.

Cheers,
Thanet, AdWords API Team
Reply all
Reply to author
Forward
0 new messages