$totalNumEntries = 0;
do {
// Retrieve ad group ads one page at a time, continuing to request pages
// until all ad group ads have been retrieved.
$page = $adGroupAdService->get($selector);
// Print out some information for each ad group ad.
if ($page->getEntries() !== null) {
$totalNumEntries = $page->getTotalNumEntries();
foreach ($page->getEntries() as $adGroupAd) {
printf(
"Expanded text ad with ID %d, status '%s', and headline '%s - %s' was found.\n",
$adGroupAd->getAd()->getId(),
$adGroupAd->getStatus(),
$adGroupAd->getAd()->getHeadlinePart1(),
$adGroupAd->getAd()->getHeadlinePart2(),
$adGroupAd->getLink() // Link to site? https://site.com
);
}
}
$selector->getPaging()->setStartIndex(
$selector->getPaging()->getStartIndex() + self::PAGE_LIMIT
);
} while ($selector->getPaging()->getStartIndex() < $totalNumEntries);
printf("Number of results found: %d\n", $totalNumEntries);
I found an examplehow to modify it to return a link to site page?example
class GetExpandedTextAds
{
const AD_GROUP_ID = 'INSERT_AD_GROUP_ID_HERE';
const PAGE_LIMIT = 500;
public static function runExample(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$adGroupId
) {
$adGroupAdService = $adWordsServices->get($session, AdGroupAdService::class);
// Create a selector to select all ads for the specified ad group.
$selector = new Selector();
$selector->setFields(
['Id', 'Status', 'HeadlinePart1', 'HeadlinePart2', 'Description']
);
$selector->setOrdering([new OrderBy('Id', SortOrder::ASCENDING)]);
$selector->setPredicates(
[
new Predicate('AdGroupId', PredicateOperator::IN, [$adGroupId]),
new Predicate(
'AdType',
PredicateOperator::IN,
[AdType::EXPANDED_TEXT_AD]
),
new Predicate(
'Status',
PredicateOperator::IN,
[AdGroupAdStatus::ENABLED, AdGroupAdStatus::PAUSED]
)
]
);
$selector->setPaging(new Paging(0, self::PAGE_LIMIT));
$totalNumEntries = 0;
do {
// Retrieve ad group ads one page at a time, continuing to request pages
// until all ad group ads have been retrieved.
$page = $adGroupAdService->get($selector);
// Print out some information for each ad group ad.
if ($page->getEntries() !== null) {
$totalNumEntries = $page->getTotalNumEntries();
foreach ($page->getEntries() as $adGroupAd) {
printf(
"Expanded text ad with ID %d, status '%s', and headline '%s - %s' was found.\n",
$adGroupAd->getAd()->getId(),
$adGroupAd->getStatus(),
$adGroupAd->getAd()->getHeadlinePart1(),
$adGroupAd->getAd()->getHeadlinePart2()
);
}
}
$selector->getPaging()->setStartIndex(
$selector->getPaging()->getStartIndex() + self::PAGE_LIMIT
);
} while ($selector->getPaging()->getStartIndex() < $totalNumEntries);
printf("Number of results found: %d\n", $totalNumEntries);
}
public static function main()
{
// Generate a refreshable OAuth2 credential for authentication.
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
// Construct an API session configured from a properties file and the
// OAuth2 credentials above.
$session = (new AdWordsSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->build();
self::runExample(
new AdWordsServices(),
$session,
intval(self::AD_GROUP_ID)
);
}
}
GetExpandedTextAds::main();
im add selectors