This is my code: 

class GetExpandedTextAds {

  const AD_GROUP_ID = '38776120257';
  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) {
            $adGroupAdService =
                $adWordsServices->get($session, AdGroupAdService::class);

            $operations = [];
            // Create ad using an existing ID. Use the base class Ad instead of 
TextAd
            // to avoid having to set ad-specific fields.
            $ad = new ExpandedTextAd();
            $ad->setId($adGroupAd);

            // Create ad group ad.
            $adGroupAd = new AdGroupAd();
            $adGroupAd->setAdGroupId($adGroupId);
            $adGroupAd->setAd($ad);

            // Update the status to PAUSED.
            $adGroupAd->setStatus(AdGroupAdStatus::PAUSED);

            // Create ad group ad operation and add it to the list.
            $operation = new AdGroupAdOperation();
            $operation->setOperand($adGroupAd);
            $operation->setOperator(Operator::SET);
            $operations[] = $operation;

            // Pause the ad on the server.
            $adGroupAd = $adGroupAdService->mutate($operations)->getValue()[0];
          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();


This is the error I am getting: 

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"; 
xmlns:ns1="https://adwords.google.com/api/adwords/cm/v201609"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";><SOAP-ENV:Header><ns1:RequestHeader><ns1:clientCustomerId>980-487-6449</ns1:clientCustomerId><ns1:developerToken>REDACTED</ns1:developerToken><ns1:userAgent>unknown
 (AwApi-PHP, googleads-php-lib/25.2.0, 
PHP/7.0.15-0ubuntu0.16.04.4)</ns1:userAgent><ns1:validateOnly>false</ns1:validateOnly><ns1:partialFailure>false</ns1:partialFailure></ns1:RequestHeader></SOAP-ENV:Header><SOAP-ENV:Body><ns1:mutate><ns1:operations><ns1:operator>SET</ns1:operator><ns1:operand><ns1:adGroupId>38776120257</ns1:adGroupId><ns1:ad
 xsi:type="ns1:ExpandedTextAd"><ns1:id 
xsi:type="ns1:AdGroupAd"><ns1:adGroupId>38776120257</ns1:adGroupId><ns1:ad 
xsi:type="ns1:ExpandedTextAd"><ns1:id>185071728849</ns1:id><ns1:type>EXPANDED_TEXT_AD</ns1:type><ns1:Ad.Type>ExpandedTextAd</ns1:Ad.Type><ns1:headlinePart1>212
 E Ohio2</ns1:headlinePart1><ns1:headlinePart2>Chicago,IL 
60640</ns1:headlinePart2><ns1:description>For Sale: $250,000. 4 bed, 2 bath 
detached home in Lincoln 
Park.</ns1:description></ns1:ad><ns1:status>ENABLED</ns1:status><ns1:approvalStatus>FAMILY_SAFE</ns1:approvalStatus><ns1:trademarkDisapproved>false</ns1:trademarkDisapproved></ns1:id></ns1:ad><ns1:status>PAUSED</ns1:status></ns1:operand></ns1:operations></ns1:mutate></SOAP-ENV:Body></SOAP-ENV:Envelope>

HTTP/1.1 500 Internal Server Error
Content-Type: text/xml; charset=UTF-8
Date: Mon, 13 Mar 2017 15:43:29 GMT
Expires: Mon, 13 Mar 2017 15:43:29 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Alt-Svc: quic=":443"; ma=2592000; v="36,35,34"
Accept-Ranges: none
Vary: Accept-Encoding
Transfer-Encoding: chunked

<soap:Envelope 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Unmarshalling
 Error: cvc-elt.4.3: Type 'ns1:AdGroupAd' is not validly derived from the type 
definition, 'long', of element 'ns1:id'. 
</faultstring></soap:Fault></soap:Body></soap:Envelope>
  
PHP Fatal error:  Uncaught SoapFault exception: [soap:Client] Unmarshalling 
Error: cvc-elt.4.3: Type 'ns1:AdGroupAd' is not validly derived from the type 
definition, 'long', of element 'ns1:id'.  in 
/home/danielhai/test/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/AdsSoapClient.php:115
Stack trace:
#0 
/home/danielhai/test/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/AdsSoapClient.php(115):
 SoapClient->__soapCall('mutate', Array, NULL, Array, Array)
#1 
/home/danielhai/test/vendor/googleads/googleads-php-lib/src/Google/AdsApi/AdWords/v201609/cm/AdGroupAdService.php(181):
 Google\AdsApi\Common\AdsSoapClient->__soapCall('mutate', Array)
#2 /home/danielhai/test/v201609/BasicOperations/GED.php(101): 
Google\AdsApi\AdWords\v201609\cm\AdGroupAdService->mutate(Array)
#3 /home/danielhai/test/v201609/BasicOperations/GED.php(133): 
Google\AdsApi\Examples\AdWords\v201609\BasicOperations\GetExpandedTextAds::runExample(Object(Google\AdsApi\AdWords\AdWordsServices),
 Object(Google\AdsApi\AdWords\AdWordsSession), 3877 in 
/home/danielhai/test/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/AdsSoapClient.php
 on line 115


-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/a2df948b-4e2c-4b2b-868f-71b837269a6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • PHP Fatal error... Dan Hai
    • Re: PHP Fa... 'Shwetha Vastrad (AdWords API Team)' via AdWords API Forum
      • Re: PH... Dan Hai
        • Re... 'Shwetha Vastrad (AdWords API Team)' via AdWords API Forum

Reply via email to