To get detailed information about all keywords in an ad group, you need to get information about all keywords.
require_once dirname(dirname(__FILE__)) . '/init.php';
$adGroupId = 'Enter your adgroup id';
function GetKeywordsExample(AdWordsUser $user, $adGroupId) {
$adGroupCriterionService =
$user->GetService('AdGroupCriterionService', ADWORDS_VERSION);
$selector = new Selector();
$selector->fields = array('KeywordText', 'KeywordMatchType', 'Id');
$selector->ordering[] = new OrderBy('KeywordText', 'ASCENDING');
$selector->predicates[] = new Predicate('AdGroupId', 'IN', array($adGroupId));
$selector->predicates[] =
new Predicate('CriteriaType', 'IN', array('KEYWORD'));
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
do {
$page = $adGroupCriterionService->get($selector);
if (isset($page->entries)) {
foreach ($page->entries as $adGroupCriterion) {
printf("Keyword with text '%s', match type '%s', and ID '%s' was "
. "found.\n", $adGroupCriterion->criterion->text,
$adGroupCriterion->criterion->matchType,
$adGroupCriterion->criterion->id);
}
} else {
print "No keywords were found.\n";
}
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
} while ($page->totalNumEntries > $selector->paging->startIndex);
}
if (__FILE__ != realpath($_SERVER['PHP_SELF'])) {
return;
}
try {
$user = new AdWordsUser();
$user->LogAll();
GetKeywordsExample($user, $adGroupId);
} catch (Exception $e) {
printf("An error has occurred: %s\n", $e->getMessage());
}
source
share