examples/AdWords/v201809/Extensions/AddSitelinksUsingFeeds.php
private static function createSitelinksFeed(
        AdWordsServices $adWordsServices,
        AdWordsSession $session
    ) {
        $feedService = $adWordsServices->get($session, FeedService::class);

        // Holds the IDs associated to the feeds metadata.
        $sitelinksData = [];

        // Create feed attributes.
        $textAttribute = new FeedAttribute();
        $textAttribute->setType(FeedAttributeType::STRING);
        $textAttribute->setName('Link Text');
        $finalUrlAttribute = new FeedAttribute();
        $finalUrlAttribute->setType(FeedAttributeType::URL_LIST);
        $finalUrlAttribute->setName('Link URL');
        $line2Attribute = new FeedAttribute();
        $line2Attribute->setType(FeedAttributeType::STRING);
        $line2Attribute->setName('Line 2');
        $line3Attribute = new FeedAttribute();
        $line3Attribute->setType(FeedAttributeType::STRING);
        $line3Attribute->setName('Line 3');

        // Create the feed.
        $sitelinksFeed = new Feed();
        $sitelinksFeed->setName('Feed For Sitelinks #' . uniqid());
        $sitelinksFeed->setAttributes([
                $textAttribute,
                $finalUrlAttribute,
                $line2Attribute,
                $line3Attribute
        ]);
        $sitelinksFeed->setOrigin(FeedOrigin::USER);

        // Create the feed operation and add it on the server.
        $operation = new FeedOperation();
        $operation->setOperator(Operator::ADD);
        $operation->setOperand($sitelinksFeed);
        $result = $feedService->mutate([$operation]);

        // Print out some information about the created feed.
        $savedFeed = $result->getValue()[0];
        $sitelinksData['sitelinksFeedId'] = $savedFeed->getId();
        $savedAttributes = $savedFeed->getAttributes();
        $sitelinksData['linkTextFeedAttributeId'] =
            $savedAttributes[0]->getId();
        $sitelinksData['linkFinalUrlFeedAttributeId'] =
            $savedAttributes[1]->getId();
        $sitelinksData['line2FeedAttribute'] = $savedAttributes[2]->getId();
        $sitelinksData['line3FeedAttribute'] = $savedAttributes[3]->getId();

        printf(
            "Feed with name '%s', ID %d with linkTextAttributeId %d, "
            . "linkFinalUrlAttributeId %d, line2AttributeId %d and "
            . "line3AttributeId %d was created.%s",
            $savedFeed->getName(),
            $savedFeed->getId(),
            $savedAttributes[0]->getId(),
            $savedAttributes[1]->getId(),
            $savedAttributes[2]->getId(),
            $savedAttributes[3]->getId(),
            PHP_EOL
        );

        return $sitelinksData;
    }
private static function createSitelinksFeed(
        AdWordsServices $adWordsServices,
        AdWordsSession $session
    ) {
        $feedService = $adWordsServices->get($session, FeedService::class);

        // Holds the IDs associated to the feeds metadata.
        $sitelinksData = [];

        // Create feed attributes.
        $textAttribute = new FeedAttribute();
        $textAttribute->setType(FeedAttributeType::STRING);
        $textAttribute->setName('Link Text');
        $finalUrlAttribute = new FeedAttribute();
        $finalUrlAttribute->setType(FeedAttributeType::URL_LIST);
        $finalUrlAttribute->setName('Link URL');
        $line2Attribute = new FeedAttribute();
        $line2Attribute->setType(FeedAttributeType::STRING);
        $line2Attribute->setName('Line 2');
        $line3Attribute = new FeedAttribute();
        $line3Attribute->setType(FeedAttributeType::STRING);
        $line3Attribute->setName('Line 3');

        // Create the feed.
        $sitelinksFeed = new Feed();
        $sitelinksFeed->setName('Feed For Sitelinks #' . uniqid());
        $sitelinksFeed->setAttributes([
                $textAttribute,
                $finalUrlAttribute,
                $line2Attribute,
                $line3Attribute
        ]);
        $sitelinksFeed->setOrigin(FeedOrigin::USER);

        // Create the feed operation and add it on the server.
        $operation = new FeedOperation();
        $operation->setOperator(Operator::ADD);
        $operation->setOperand($sitelinksFeed);
        $result = $feedService->mutate([$operation]);

        // Print out some information about the created feed.
        $savedFeed = $result->getValue()[0];
        $sitelinksData['sitelinksFeedId'] = $savedFeed->getId();
        $savedAttributes = $savedFeed->getAttributes();
        $sitelinksData['linkTextFeedAttributeId'] =
            $savedAttributes[0]->getId();
        $sitelinksData['linkFinalUrlFeedAttributeId'] =
            $savedAttributes[1]->getId();
        $sitelinksData['line2FeedAttribute'] = $savedAttributes[2]->getId();
        $sitelinksData['line3FeedAttribute'] = $savedAttributes[3]->getId();

        printf(
            "Feed with name '%s', ID %d with linkTextAttributeId %d, "
            . "linkFinalUrlAttributeId %d, line2AttributeId %d and "
            . "line3AttributeId %d was created.%s",
            $savedFeed->getName(),
            $savedFeed->getId(),
            $savedAttributes[0]->getId(),
            $savedAttributes[1]->getId(),
            $savedAttributes[2]->getId(),
            $savedAttributes[3]->getId(),
            PHP_EOL
        );

        return $sitelinksData;
    }
private static function createSitelinksFeed ( AdWordsServices $ adWordsServices , AdWordsSession $ session ) { $ feedService = $ adWordsServices -> get ( $ session , FeedService :: class ) ; // Holds the IDs associated to the feeds metadata. $ sitelinksData = [ ] ; // Create feed attributes. $ textAttribute = new FeedAttribute ( ) ; $ textAttribute -> setType ( FeedAttributeType :: STRING ) ; $ textAttribute -> setName ( 'Link Text' ) ; $ finalUrlAttribute = new FeedAttribute ( ) ; $ finalUrlAttribute -> setType ( FeedAttributeType :: URL_LIST ) ; $ finalUrlAttribute -> setName ( 'Link URL' ) ; $ line2Attribute = new FeedAttribute ( ) ; $ line2Attribute -> setType ( FeedAttributeType :: STRING ) ; $ line2Attribute -> setName ( 'Line 2' ) ; $ line3Attribute = new FeedAttribute ( ) ; $ line3Attribute -> setType ( FeedAttributeType :: STRING ) ; $ line3Attribute -> setName ( 'Line 3' ) ; // Create the feed. $ sitelinksFeed = new Feed ( ) ; $ sitelinksFeed -> setName ( 'Feed For Sitelinks #' . uniqid ( ) ) ; $ sitelinksFeed -> setAttributes ( [ $ textAttribute , $ finalUrlAttribute , $ line2Attribute , $ line3Attribute ] ) ; $ sitelinksFeed -> setOrigin ( FeedOrigin :: USER ) ; // Create the feed operation and add it on the server. $ operation = new FeedOperation ( ) ; $ operation -> setOperator ( Operator :: ADD ) ; $ operation -> setOperand ( $ sitelinksFeed ) ; $ result = $ feedService -> mutate ( [ $ operation ] ) ; // Print out some information about the created feed. $ savedFeed = $ result -> getValue ( ) [ 0 ] ; $ sitelinksData [ 'sitelinksFeedId' ] = $ savedFeed -> getId ( ) ; $ savedAttributes = $ savedFeed -> getAttributes ( ) ; $ sitelinksData [ 'linkTextFeedAttributeId' ] = $ savedAttributes [ 0 ] -> getId ( ) ; $ sitelinksData [ 'linkFinalUrlFeedAttributeId' ] = $ savedAttributes [ 1 ] -> getId ( ) ; $ sitelinksData [ 'line2FeedAttribute' ] = $ savedAttributes [ 2 ] -> getId ( ) ; $ sitelinksData [ 'line3FeedAttribute' ] = $ savedAttributes [ 3 ] -> getId ( ) ; printf ( "Feed with name '%s', ID %d with linkTextAttributeId %d, " . "linkFinalUrlAttributeId %d, line2AttributeId %d and " . "line3AttributeId %d was created.%s" , $ savedFeed -> getName ( ) , $ savedFeed -> getId ( ) , $ savedAttributes [ 0 ] -> getId ( ) , $ savedAttributes [ 1 ] -> getId ( ) , $ savedAttributes [ 2 ] -> getId ( ) , $ savedAttributes [ 3 ] -> getId ( ) , PHP_EOL ) ; return $ sitelinksData ; }
Creates the feed that holds the sitelinks data.
Creates the feed that holds the sitelinks data .