Extension SiteLink Google ads php

105 views
Skip to first unread message

Adrian Lara

unread,
Jun 27, 2019, 12:24:23 PM6/27/19
to AdWords API and Google Ads API Forum
Hi Google Ads,

I am trying to perform SiteLink type extension, but it is becoming impossible due to lack of documentation. Someone to tell me if I'm going well.

<code>
use Google\Protobuf\StringValue;
use Google\ApiCore\ApiException;
use Google\Ads\GoogleAds\Util\V1\ResourceNames;
use Google\Ads\GoogleAds\V1\Common\AdScheduleInfo;
use Google\Ads\GoogleAds\Lib\V1\GoogleAdsException;
use Google\Ads\GoogleAds\V1\Common\SitelinkFeedItem;
use Google\Ads\GoogleAds\V1\Resources\ExtensionFeedItem;
use Google\Ads\GoogleAds\V1\Resources\AdGroupExtensionSetting;
use Google\Ads\GoogleAds\V1\Enums\ExtensionTypeEnum\ExtensionType;
use Google\Ads\GoogleAds\V1\Services\AdGroupExtensionSettingOperation;
use Google\Ads\GoogleAds\V1\Enums\DayOfWeekEnum\DayOfWeek;
use Google\Ads\GoogleAds\V1\Enums\MinuteOfHourEnum\MinuteOfHour;

 private function newAdScheduleInfo($nameDayOfWeek,$startMinute,$endMinute,$startHour,$endHour){
  
  $adScheduleInfo = new AdScheduleInfo();
  $adScheduleInfo ->setDayOfWeek( (new DayOfWeek)->value($nameDayOfWeek) );
  $adScheduleInfo ->setStartMinute( (new MinuteOfHour)->value($startMinute) );
  $adScheduleInfo ->setEndMinute( (new MinuteOfHour)->value($endMinute) );
  $adScheduleInfo ->setStartHourValue($startHour);
  $adScheduleInfo ->setEndHourValue($endHour);
  return $adScheduleInfo;
 }

 private function newSiteLinkOption($linkUrl,$link_text, $line1, $line2){ 
  $sitelink = new SitelinkFeedItem();
  $sitelink->setLinkTextValue($link_text);
  $sitelink->setLine2Value($line2);
  $sitelink->setLine1Value($line1);
  $sitelink->setFinalUrls( [ new StringValue( [ 'value' => $linkUrl ] ) ] );
  return $sitelink;
 }


$operations = [];
   $adGroupResourceName =new StringValue( [ 'value' => ResourceNames::forAdGroup($this->customerId, $groupId) ] );
   $adScheduleInfo = [];
   $days = ['MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY','FRIDAY'];
   foreach ($days  as $day) {
    $adScheduleInfo[] = $this->newAdScheduleInfo($day,'ZERO','ZERO',0,24);
   }
  
   $sitelink_feed_item = $this->newSiteLinkOption('https://experimax.com','Support Experimax', 'Desc 1 ', 'Desc 2' );
   if(!$sitelink_feed_item){
    return false;
   }
  
   $extensionFeedItem = new ExtensionFeedItem([
    'sitelink_feed_item' => $sitelink_feed_item,
    'ad_schedules' => $adScheduleInfo,
    'start_date_time' => "2021-03-05 09:00:00",
    'end_date_time'   => "2024-03-05 08:00:00",
   ]);
   
   $adGroupExtensionSetting = new AdGroupExtensionSetting([
    'ad_group'        => $adGroupResourceName,
    'extension_type'     => ExtensionType::SITELINK,
    'extension_feed_items' => [$extensionFeedItem->getResourceName()]
   ]);
  
   $adGroupExtensionSettingOperation = new AdGroupExtensionSettingOperation();
   $adGroupExtensionSettingOperation->setCreate($adGroupExtensionSetting);
   $operations[] = $adGroupExtensionSettingOperation;

   $adGroupExtensionSettingServiceClient = $this->service->getAdGroupExtensionSettingServiceClient();
   $response = $adGroupExtensionSettingServiceClient->mutateAdGroupExtensionSettings($this->customerId, $operations);

</code>

<error>
string(1102) "{
    "message": "Request contains an invalid argument.",
    "code": 3,
    "status": "INVALID_ARGUMENT",
    "details": [
        {
            "@type": 0,
            "data": "type.googleapis.com\/google.ads.googleads.v1.errors.GoogleAdsFailure"
        },
        {
            "@type": 0,
            "data": [
                {
                    "errorCode": {
                        "requestError": "RESOURCE_NAME_MISSING"
                    },
                    "message": "Resource name is missing.",
                    "location": {
                        "fieldPathElements": [
                            {
                                "fieldName": "operations",
                                "index": "0"
                            },
                            {
                                "fieldName": "create"
                            },
                            {
                                "fieldName": "extension_feed_items"
                            }
                        ]
                    }
                }
            ]
        }
    ]

</error>



Google Ads API Forum Advisor Prod

unread,
Jun 28, 2019, 4:07:24 AM6/28/19
to adr...@das-group.com, adwor...@googlegroups.com

Hi Adrian,

Thank you for reaching out.

The error you are encountering INVALID_ARGUMENT, based from the description, means that you are missing a resource name that is required in one of your operations.

Upon checking the code you've provided, it seems that you are passing the correct parameters. However, since I am not that knowledgeable in PHP, could you provide the complete JSON request and response logs so I could further investigate this? You may refer to this guide on how to enable logging in your library. You may use the reply privately to author option.

Regards,
Dannison
Google Ads API Team



ref:_00D1U1174p._5001UCZr1z:ref

Adrian Lara

unread,
Jun 28, 2019, 8:49:51 AM6/28/19
to AdWords API and Google Ads API Forum
ok, the problem in my investigation is  here:

$extensionFeedItem = new ExtensionFeedItem([
    'sitelink_feed_item' => $sitelink_feed_item,
    'ad_schedules' => $adScheduleInfo,
    'start_date_time' => "2021-03-05 09:00:00",
    'end_date_time'   => "2024-03-05 08:00:00",
    'extension_type'  => ExtensionType::SITELINK,
    'status' => (new FeedItemStatus)->value('ENABLED')
   ]);
   
return $extensionFeedItem->getResourceName();

   $adGroupExtensionSetting = new AdGroupExtensionSetting([
    'ad_group'        => $adGroupResourceName,
    'extension_type'     => ExtensionType::SITELINK,
    'extension_feed_items' => [$extensionFeedItem->getResourceName()]
   ]);

the Output is empty and parameter 'extension_feed_items' required this information.

Capture.PNG

Adrian Lara

unread,
Jun 30, 2019, 1:53:31 PM6/30/19
to AdWords API and Google Ads API Forum
Any Update??


On Friday, June 28, 2019 at 5:07:24 AM UTC-3, adsapiforumadvisor wrote:

Adrian Lara

unread,
Jul 1, 2019, 10:35:57 AM7/1/19
to AdWords API and Google Ads API Forum
Ready, I need add this:

$operationObject  = new ExtensionFeedItemOperation();
$operationObject
->setCreate($operation);
$adGroupExtensionSettingServiceClient
= $this->service->getExtensionFeedItemServiceClient();
$adGroupExtensionSettingServiceClient->mutateExtensionFeedItems($this->customerId, $operations);


Google Ads API Forum Advisor Prod

unread,
Jul 1, 2019, 2:45:41 PM7/1/19
to adr...@das-group.com, adwor...@googlegroups.com
Hello Adrian, 

Could you please confirm if you need additional assistance creating the Sitelink Extensions through the API? If so, could you please share the request and response logs which contain the error details, to check this further? You can share the details privately via Reply privately to author option. 

Regards,
Bharani, Google Ads API Team
 

ref:_00D1U1174p._5001UCZr1z:ref

Adrian Lara

unread,
Jul 16, 2019, 9:19:44 AM7/16/19
to AdWords API and Google Ads API Forum
Now is good, after add code(before post) now is good ty for you help.
Reply all
Reply to author
Forward
0 new messages