Load an Ad By Id

29 views
Skip to first unread message

dim...@sponsorboost.com

unread,
Jun 27, 2017, 10:33:34 AM6/27/17
to AdWords API Forum
Hi All,

I want to manage Adwords Ads from my interface.

But I have a problem to get Ad detail from id.
I try to use predicate in selector with AdGroupAd but field 'AdId' or 'Ad' is bad and I have an error.

So I don't know how I can get an Ad by id.


This is more information :
- I use PHP package
 - composer package version : "googleads/googleads-php-lib": "^27.1"
- Google version : v201705
- use Sandbox account

This is how I get ads from AdGroupId :
$adGroupAdService = $this->getGoogleService($session, AdGroupAdService::class);
$predicate = new Predicate('AdGroupId', PredicateOperator::IN, ['39244037650']);// TODO dynamic
$adGroupAds = $this->getGoogleData($adGroupAdService, $this->getGoogleField('ad'), [], [$predicate]);
foreach ($adGroupAds as $adGroupAd){
var_dump($adGroupAd->getAd());
}

It works but it's the best way ? There are not other solution ?


And this is how I try to get an Ad by Id :
$adGroupAdService = $this->getGoogleService($session, AdGroupAdService::class);
//$predicate = new Predicate('Ad', PredicateOperator::IN, ['203114498124']);// TODO dynamic
$predicate = new Predicate('AdId', PredicateOperator::IN, ['203114498124']);// TODO dynamic
$adGroupAds = $this->getGoogleData($adGroupAdService, $this->getGoogleField('ad'), [], [$predicate]);
foreach ($adGroupAds as $adGroupAd){
var_dump($adGroupAd->getAd());
}

There are no AdService class, so I try to use predicate and AdGroupAdService to load Ad by id but fields 'AdId' and 'Ad' don't works.
This is error : [SelectorError.INVALID_PREDICATE_FIELD_NAME @ serviceSelector; trigger:'AdId']

I understand fields 'AdId' and 'Ad' are unavailable with AdGroupAd but how I can do to load Ad by Id properly ?


Other information :  I have no problem to load report by Ad


If you need more information tell me :)

Thanks

Shwetha Vastrad (AdWords API Team)

unread,
Jun 27, 2017, 1:54:16 PM6/27/17
to AdWords API Forum
Hi, 

Yes, AdId and Ad are not one of the supported fields for AdGroupAdService. Please see this document for the list of supported fields for AdGroupAdService. You need to use the Id field in the predicate to filter based on the ID of an Ad. 

Regards,
Shwetha, AdWords API Team.

dim...@sponsorboost.com

unread,
Jun 28, 2017, 3:41:27 AM6/28/17
to AdWords API Forum
Thank you so much ! It's working :)
Reply all
Reply to author
Forward
0 new messages