Ipblock adwords api php???

173 views
Skip to first unread message

man...@devmako.sk

unread,
Feb 6, 2017, 5:00:46 AM2/6/17
to AdWords API Forum
Hello
i write this code but its not correct.
Any ideas??? Or is the other way???


Fatal error: Cannot access protected property

use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSession;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\AdWords\v201609\cm\AdGroupCriterionOperation;
use Google\AdsApi\AdWords\v201609\cm\AdGroupCriterionService;
use Google\AdsApi\AdWords\v201609\cm\AdGroupCriterion;
use Google\AdsApi\AdWords\v201609\cm\AdGroupCriterionServiceInterface;
use Google\AdsApi\AdWords\v201609\cm\AdGroupCriterionReturnValue;
use Google\AdsApi\AdWords\v201609\cm\Criterion;
use Google\AdsApi\AdWords\v201609\cm\Operator;
use Google\AdsApi\AdWords\v201609\cm\Selector;
use Google\AdsApi\AdWords\v201609\cm\Predicate;
use Google\AdsApi\AdWords\v201609\cm\Placement;
use Google\AdsApi\Common\OAuth2TokenBuilder;


class Updateip {
const campaignId = '....';
protected $selector;
  public static function runExample(
     AdWordsServices $adWordsServices,
      AdWordsSession $session) {
    // Get the AdGroupCriterionService.

    $adGroupCriterionService =
        $adWordsServices->get($session, AdGroupCriterionService::class);

  $selector = new Selector();

$selector->predicates[] = new Predicate('CampaignId', 'IN', array($campaignId));
$selector->predicates[] = new Predicate('CriteriaType', 'IN', array('IP_BLOCK'));
$selector->predicates[] = new Predicate('ipAddress', 'IN', array('10.10.10.10'));
$page = $campaignCriterionService->get($selector);
print_r($page);

  }

  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);
  }
}

Updateip::main();



Thanks 
MK

Shwetha Vastrad (AdWords API Team)

unread,
Feb 6, 2017, 2:00:40 PM2/6/17
to AdWords API Forum
Hi,

IpBlock is a negative criterion that should be applied at the campaign level. You need to use CampaignCriterionService to retrieve your CampaignCriterion. The predicates, fields, etc. of a selector are protected variables in the PHP client library. This is the reason you encounter errors when you execute your program. You need to use the corresponding setters to populate these fields as shown here. Could you try this out and let me know if it works? 

Regards,
Shwetha, AdWords API Team.
Reply all
Reply to author
Forward
0 new messages