examples/AdWords/v201809/Extensions/AddSitelinksUsingFeeds.php
private static function createSitelinksCampaignFeed(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        array $sitelinksData,
        $campaignId
    ) {
        $campaignFeedService =
            $adWordsServices->get($session, CampaignFeedService::class);
        $matchingFunctionString = sprintf(
            'AND( IN(FEED_ITEM_ID, {%s}), EQUALS(CONTEXT.DEVICE, "Mobile") )',
            implode(',', $sitelinksData['sitelinkFeedItemIds'])
        );

        // Create a campaign feed and its feed function.
        $campaignFeed = new CampaignFeed();
        $campaignFeed->setFeedId($sitelinksData['sitelinksFeedId']);
        $campaignFeed->setCampaignId($campaignId);

        $matchingFunction = new MatchingFunction();
        $matchingFunction->setFunctionString($matchingFunctionString);
        $campaignFeed->setMatchingFunction($matchingFunction);
        $campaignFeed->setPlaceholderTypes([self::PLACEHOLDER_SITELINKS]);

        // Create the campaign feed operation.
        $operation = new CampaignFeedOperation();
        $operation->setOperand($campaignFeed);
        $operation->setOperator(Operator::ADD);

        // Create the campaign feed on the server and print out some information.
        $result = $campaignFeedService->mutate([$operation]);
        foreach ($result->getValue() as $savedCampaignFeed) {
            printf(
                'Campaign with ID %d was associated with feed with ID %d.%s',
                $savedCampaignFeed->getCampaignId(),
                $savedCampaignFeed->getFeedId(),
                PHP_EOL
            );
        }
    }
private static function createSitelinksCampaignFeed(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        array $sitelinksData,
        $campaignId
    ) {
        $campaignFeedService =
            $adWordsServices->get($session, CampaignFeedService::class);
        $matchingFunctionString = sprintf(
            'AND( IN(FEED_ITEM_ID, {%s}), EQUALS(CONTEXT.DEVICE, "Mobile") )',
            implode(',', $sitelinksData['sitelinkFeedItemIds'])
        );

        // Create a campaign feed and its feed function.
        $campaignFeed = new CampaignFeed();
        $campaignFeed->setFeedId($sitelinksData['sitelinksFeedId']);
        $campaignFeed->setCampaignId($campaignId);

        $matchingFunction = new MatchingFunction();
        $matchingFunction->setFunctionString($matchingFunctionString);
        $campaignFeed->setMatchingFunction($matchingFunction);
        $campaignFeed->setPlaceholderTypes([self::PLACEHOLDER_SITELINKS]);

        // Create the campaign feed operation.
        $operation = new CampaignFeedOperation();
        $operation->setOperand($campaignFeed);
        $operation->setOperator(Operator::ADD);

        // Create the campaign feed on the server and print out some information.
        $result = $campaignFeedService->mutate([$operation]);
        foreach ($result->getValue() as $savedCampaignFeed) {
            printf(
                'Campaign with ID %d was associated with feed with ID %d.%s',
                $savedCampaignFeed->getCampaignId(),
                $savedCampaignFeed->getFeedId(),
                PHP_EOL
            );
        }
    }
private static function createSitelinksCampaignFeed ( AdWordsServices $ adWordsServices , AdWordsSession $ session , array $ sitelinksData , $ campaignId ) { $ campaignFeedService = $ adWordsServices -> get ( $ session , CampaignFeedService :: class ) ; $ matchingFunctionString = sprintf ( 'AND( IN(FEED_ITEM_ID, {%s}), EQUALS(CONTEXT.DEVICE, "Mobile") )' , implode ( ',' , $ sitelinksData [ 'sitelinkFeedItemIds' ] ) ) ; // Create a campaign feed and its feed function. $ campaignFeed = new CampaignFeed ( ) ; $ campaignFeed -> setFeedId ( $ sitelinksData [ 'sitelinksFeedId' ] ) ; $ campaignFeed -> setCampaignId ( $ campaignId ) ; $ matchingFunction = new MatchingFunction ( ) ; $ matchingFunction -> setFunctionString ( $ matchingFunctionString ) ; $ campaignFeed -> setMatchingFunction ( $ matchingFunction ) ; $ campaignFeed -> setPlaceholderTypes ( [ self :: PLACEHOLDER_SITELINKS ] ) ; // Create the campaign feed operation. $ operation = new CampaignFeedOperation ( ) ; $ operation -> setOperand ( $ campaignFeed ) ; $ operation -> setOperator ( Operator :: ADD ) ; // Create the campaign feed on the server and print out some information. $ result = $ campaignFeedService -> mutate ( [ $ operation ] ) ; foreach ( $ result -> getValue ( ) as $ savedCampaignFeed ) { printf ( 'Campaign with ID %d was associated with feed with ID %d.%s' , $ savedCampaignFeed -> getCampaignId ( ) , $ savedCampaignFeed -> getFeedId ( ) , PHP_EOL ) ; } }
Creates the campaign feed associated to the populated feed data for the
specified campaign ID.
Creates the campaign feed associated to the populated feed data for the specified campaign ID .