Skip to content

Instantly share code, notes, and snippets.

@jamesmills
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmills/af9206f88b1e0880b281 to your computer and use it in GitHub Desktop.
Save jamesmills/af9206f88b1e0880b281 to your computer and use it in GitHub Desktop.
This will associate a given FeedItem with an AdGroup.
<?php
protected function createCallAdGroupFeed(AdWordsUser $user, $feed, $feed_item, $adgroup)
{
// Get the CampaignFeedService, which loads the required classes.
$adGroupFeedService = $user->GetService('AdGroupFeedService');
$feedFunctionRequestContextOperand = new RequestContextOperand();
$feedFunctionRequestContextOperand->contextType = 'FEED_ITEM_ID';
$feedItemFunction = new FeedFunction();
$feedItemFunction->lhsOperand = array($feedFunctionRequestContextOperand);
$feedItemFunction->operator = 'IN';
$constantOperand = new ConstantOperand();
$constantOperand->longValue = $feed_item->feedItemId;
$constantOperand->type = 'LONG';
$operands[] = $constantOperand;
$feedItemFunction->rhsOperand = $operands;
# Optional: to target to a platform, define a function and 'AND' it with the feed item ID link:
$platformRequestContextOperand = new RequestContextOperand();
$platformRequestContextOperand->contextType = 'DEVICE_PLATFORM';
$platformOperand = new ConstantOperand();
$platformOperand->type = 'STRING';
$platformOperand->stringValue = 'Mobile';
$platformFunction = new FeedFunction();
$platformFunction->operator = 'EQUALS';
$platformFunction->lhsOperand = array($platformRequestContextOperand);
$platformFunction->rhsOperand = array($platformOperand);
$feedItemFunctionOperand = new FunctionOperand();
$feedItemFunctionOperand->value = $feedItemFunction;
$platformFunctionOperand = new FunctionOperand();
$platformFunctionOperand->value = $platformFunction;
$combinedFunction = new FeedFunction();
$combinedFunction->operator = 'AND';
$combinedFunction->lhsOperand = array($feedItemFunctionOperand, $platformFunctionOperand);
$adGroupFeed = new AdGroupFeed();
$adGroupFeed->feedId = $feed->id;
$adGroupFeed->adGroupId = $adgroup->id;
$adGroupFeed->matchingFunction = $combinedFunction;
$adGroupFeed->placeholderTypes = array(PLACEHOLDER_CALL);
$operation = new AdGroupFeedOperation();
$operation->operand = $adGroupFeed;
$operation->operator = 'ADD';
$result = $adGroupFeedService->mutate($operation);
return $result->value[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment