Image ad create usingn API

117 views
Skip to first unread message

denma test

unread,
Jul 29, 2020, 9:30:33 AM7/29/20
to AdWords API and Google Ads API Forum
Cannot create imageAd using adwords API. Am using "use Google\AdsApi\AdWords\v201809\cm\ImageAd;" it throws errors as

 [errorString:protected] => AdError.EMPTY_FIELD
                    [ApiErrorType:protected] => AdError
                    [parameterMap:Google\AdsApi\AdWords\v201809\cm\ApiError:private] => Array
                        (
                            [ApiError.Type] => ApiErrorType
                        )

                )

            [1] => Google\AdsApi\AdWords\v201809\cm\AdError Object
                (
                    [reason:protected] => EMPTY_FIELD
                    [fieldPath:protected] => operations[0].operand.ad.displayUrl

but in imageAds class file there is no getter setter for
displayUrl. Anyone can please help me to sort it out. Thanks.

Google Ads API Forum Advisor Prod

unread,
Jul 29, 2020, 12:50:10 PM7/29/20
to denm...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for reaching out. You should be able to set the displayUrl field of the ImageAd object. If you are still having issues, please share your code as well as your complete detailed request and response logs via Reply privately to author so I can further investigate the issue. You can find information on enabling logging in the ReadMe of your client library.

Regards,
Mitchell
Google Ads API Team

ref:_00D1U1174p._5004Q22ZyiL:ref

denma test

unread,
Jul 30, 2020, 12:46:16 AM7/30/20
to AdWords API and Google Ads API Forum
Sorry, actually i found the fixes, since the imageAd class extends creative class which has display URL getter setter. Now am stuck with upload image process,

public function addImage(){
        $session = self::setSession();
        $adWordsServices = new AdWordsServices();
        $assetService = $adWordsServices->get($session, AssetService::class);
        $adGroupAdService = $adWordsServices->get($session, AdGroupAdService::class);
        $adGroupId = '104834039189';

        $ImageAd = new ImageAd();

        $ImageAd->setName('ad imagesss');

        $ImageAd->setDisplayUrl('https://mydisplayurl.com');

         // Set a marketing image.
        $marketingImageAsset = new imageAsset();
 
        $marketingImageAsset->setAssetId(
            self::uploadImageAsset($assetService, 'http://xxxx/Download/test_img.jpeg')
        );

         $ImageAd->setImage([
            new AssetLink(
                $marketingImageAsset
            )]
        );

         // Create ad group ad.
        $adGroupAd = new AdGroupAd();
        $adGroupAd->setAdGroupId($adGroupId);
        $adGroupAd->setAd($ImageAd);

        // Create ad group ad operation and add it to the list.
        $operation = new AdGroupAdOperation();
        $operation->setOperand($adGroupAd);
        $operation->setOperator(Operator::ADD);

        // Add a responsive display ad on the server.
        try{
            $result = $adGroupAdService->mutate([$operation]);
            $success = array('success');
            return $success;
        }catch (ApiException $apiException) {
            return $apiException;
        }

Issue:

[errorString:protected] => AdError.EMPTY_FIELD
                    [ApiErrorType:protected] => AdError
                    [parameterMap:Google\AdsApi\AdWords\v201809\cm\ApiError:private] => Array
                        (
                            [ApiError.Type] => ApiErrorType
                        )

                )

            [1] => Google\AdsApi\AdWords\v201809\cm\NullError Object
                (
                    [reason:protected] => NULL_CONTENT
                    [fieldPath:protected] => operations[0].operand.ad.image.data

Google Ads API Forum Advisor Prod

unread,
Jul 30, 2020, 9:22:04 AM7/30/20
to denm...@gmail.com, adwor...@googlegroups.com
Hi,

You can follow this sample for uploading an image asset. It looks like you are setting the assetId instead of the assetData in your code.

denma test

unread,
Jul 31, 2020, 1:51:43 AM7/31/20
to AdWords API and Google Ads API Forum
Thanks for quick response, let me check with it. Now am looking to setup API for reporting started with campaign performance. I have done with the sample provided and report is fetching from API, i just want to convert report data into array to render in UI table. Can you please let me know how to do it.

/**
 * Downloads CRITERIA_PERFORMANCE_REPORT for the specified client customer ID.
 */
class DownloadCriteriaReportWithAwql
{

    public static function runExample(AdWordsSession $session, $reportFormat)
    {
        // Create report query to get the data for last 7 days.
        $query = (new ReportQueryBuilder())
            ->select([
                'CampaignId',
                'CampaignName',
                'CampaignStatus',
                'Impressions',
                'Clicks',
                'Cost'
            ])
            ->from(ReportDefinitionReportType::CAMPAIGN_PERFORMANCE_REPORT)
            ->where('CampaignStatus')->in(['ENABLED', 'PAUSED'])
            ->duringDateRange(ReportDefinitionDateRangeType::LAST_7_DAYS)
            ->build();

        // Download report as a string.
        $reportDownloader = new ReportDownloader($session);
        // Optional: If you need to adjust report settings just for this one
        // request, you can create and supply the settings override here.
        // Otherwise, default values from the configuration
        // file (adsapi_php.ini) are used.
        $reportSettingsOverride = (new ReportSettingsBuilder())
            ->includeZeroImpressions(true)
            ->build();
        $reportDownloadResult = $reportDownloader->downloadReportWithAwql(
            sprintf('%s', $query),
            $reportFormat,
            $reportSettingsOverride
        );
        // print_r($reportDownloadResult);
        print "Report was downloaded and printed below:\n";
        print $reportDownloadResult->getAsString();
    }

    public static function index()
    {
        // Generate a refreshable OAuth2 credential for authentication.
        $oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();

        // See: AdWordsSessionBuilder for setting a client customer ID that is
        // different from that specified in your adsapi_php.ini file.
        // Construct an API session configured from a properties file and the
        // OAuth2 credentials above.
        $session = (new AdWordsSessionBuilder())
            ->fromFile()
            ->withOAuth2Credential($oAuth2Credential)
            ->build();

        self::runExample($session, DownloadFormat::CSV);
    }
}

DownloadCriteriaReportWithAwql::index();

Google Ads API Forum Advisor Prod

unread,
Jul 31, 2020, 10:43:35 AM7/31/20
to denm...@gmail.com, adwor...@googlegroups.com
Hi,

Please see here for the supported report formats. You can specify the desired one in this line: "self::runExample($session, DownloadFormat::CSV);"
Reply all
Reply to author
Forward
0 new messages