简体   繁体   中英

Error when creating adwords campign using api

I'm using google adwords api to create campaign directly from wordpress post or page by adding campaign name, keywords, budget etc.

$campaignService = $adWordsServices->get($session, CampaignService::class);
        $campaignService->SetClientId( 'xxxxxxxxxx' );
        $operations = [];

        // Create a campaign with required and optional settings.
        $campaign = new Campaign();
        $campaign->setName('Interplanetary Cruise #' . uniqid());
        $campaign->setAdvertisingChannelType(AdvertisingChannelType::SEARCH);

But I'm having the next error:

[OperationAccessDenied.ADD_OPERATION_NOT_PERMITTED @ operations[0], OperationAccessDenied.ADD_OPERATION_NOT_PERMITTED @ operations[1]]

It seems we need to set customer id for this so we are using SetClientId() but its giving another error of

Function ("SetClientId") is not a valid method for this service

If you want to change/set the clientCustomerId with php sdk you have to do so when creating Adwords Session:

$session = (new AdWordsSessionBuilder())
    ->fromFile()
    ->withOAuth2Credential($oAuth2Credential)
    ->withClientCustomerId(clientCustomerId)
    ->build();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM