Good day Vincent,

I am still confused why I can't update the bid of the placement.
Here is my code:

<?php
/**
 * Copyright 2017 Google Inc. All Rights Reserved.
 */
namespace Google\AdsApi\Examples\AdWords\v201705\CampaignManagement;

require __DIR__ . '/../../vendor/autoload.php';

use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSession;
use Google\AdsApi\AdWords\AdWordsServicesInterface;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\AdWords\v201705\cm\AdGroupCriterionOperation;
use Google\AdsApi\AdWords\v201705\cm\AdGroupCriterionReturnValue;
use Google\AdsApi\AdWords\v201705\cm\AdGroupCriterionService;
use Google\AdsApi\AdWords\v201705\cm\BiddableAdGroupCriterion;
use Google\AdsApi\AdWords\v201705\cm\Operator;
use Google\AdsApi\AdWords\v201705\cm\Placement;
use Google\AdsApi\AdWords\v201705\cm\Platform;
use Google\AdsApi\Common\OAuth2TokenBuilder;

/**
 * This example sets a bid modifier on a campaign.
 */
class SetBidModifierInPlacement {
  const AD_GROUP_ID = '49443081811';
  const BID_MODIFIER = '1.5';

  public static function runExample(AdWordsServices $adWordsServices,
      AdWordsSession $session) {
    $campaignCriterionService =
        $adWordsServices->get($session, AdGroupCriterionService::class);

    //Create a mobile platform. The ID can be found in the documentation.
    //https://developers.google.com/adwords/api/docs/appendix/platforms
    $desktop= new Platform();
    $desktop->setId(30000); // HighEndMobile = 30001
    $urlPlacement = new Placement();
    $urlPlacement->setUrl('listverse.com');
    $urlPlacement->setId('0');
    // Create a criterion with modified bid.
    $adGroup = new BiddableAdGroupCriterion();
    $adGroup->setAdGroupId($AD_GROUP_ID );
    $adGroup->setCriterion($urlPlacement);
    $adGroup->setBidModifier($bidModifier);

    // Create a campaign criterion operation and add it to the operations 
list.
    $operation = new AdGroupCriterionOperation();
    $operation->setOperator(Operator::SET);
    $operation->setOperand($adGroup);
    $operations = [$operation];

    // Update campaign criteria on the server.
    $results = $adGroupCriterionService->mutate($operations);

    // Print out some information about the updated campaign criterion.
    foreach ($results->getValue() as $adGroupCriterion) {
      printf(
          "Campaign criterion with campaign ID %d, criterion ID %d, "
              . "and type '%s' was modified with bid %.2f.\n",
          $AdGroupCriterion->getAdGroupId(),
          $AdGroupCriterion->getCriterion()->getId(),
          $AdGroupCriterion->getCriterion()->getType(),
          $AdGroupCriterion->getBidModifier());
    }
  }

  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),
       floatval(self::BID_MODIFIER));
  }
}

SetBidModifierInPlacement::main();

End

I am getting the error:

*Fatal error*: Call to a member function mutate() on null.

Please enlighten me.

Thank you so much,
Ben

On Wednesday, October 4, 2017 at 5:03:30 PM UTC+8, Vincent Racaza (AdWords 
API Team) wrote:
>
> Hi Ben,
>
> If what you meant is the actual value of the placement ID, then you can 
> use the AdGroupCriterionService.get() 
> <https://developers.google.com/adwords/api/docs/reference/v201708/AdGroupCriterionService#get>
>  and 
> filter it by PLACEMENT criterionType 
> <https://developers.google.com/adwords/api/docs/reference/v201708/AdGroupCriterionService.Placement#criteriontype>
>  (and 
> other fields that you can filter) to get the id and other fields of the 
> placement. You can refer to the sample SOAP request snippet below:
>
> <soapenv:Body>
>     <get xmlns="https://adwords.google.com/api/adwords/cm/v201708";>
>         <serviceSelector>
>             <fields>Id</fields>
>             <fields>CriteriaType</fields>
>             <fields>BidModifier</fields>
>             <fields>PlacementUrl</fields>
>             <predicates>
>                 <field>CriteriaType</field>
>                 <operator>EQUALS</operator>
>                 <values>PLACEMENT</values>
>             </predicates>
>             <paging>
>                 <startIndex>0</startIndex>
>                 <numberResults>100</numberResults>
>             </paging>
>         </serviceSelector>
>     </get>
> </soapenv:Body>
>
> For the urlPlacement.setId(XXXX) line, the ID must be the preferred 
> placement ID on which you would like to update. In your scenario, it would 
> be the ID of your "listverse.com" placement. 
>
> Thanks,
> Vincent
> AdWords API Team
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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/82f14f4d-7804-47ff-951b-8f5a2ea27b53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • Where can I chec... bruce
    • Re: Where c... 'Vincent Racaza (AdWords API Team)' via AdWords API Forum
      • Re: Whe... bruce
        • Re:... 'Vincent Racaza (AdWords API Team)' via AdWords API Forum
          • ... bruce
            • ... 'Vincent Racaza (AdWords API Team)' via AdWords API Forum
              • ... bruce
              • ... bruce
                • ... 'Vincent Racaza (AdWords API Team)' via AdWords API Forum
                • ... bruce
                • ... 'Vincent Racaza (AdWords API Team)' via AdWords API Forum
                • ... bruce

Reply via email to