googleads / googleads-php-lib

Google Ad Manager SOAP API Client Library for PHP
Apache License 2.0
655 stars 768 forks source link

Activating / Deactivating Creative #782

Closed illusive-ch closed 1 year ago

illusive-ch commented 1 year ago

When activating or deactivating the creative I get the following error

<soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>[PermissionError.PERMISSION_DENIED @ ]</faultstring><detail><ApiExceptionFault xmlns="https://www.google.com/apis/ads/publisher/v202302"><message>[PermissionError.PERMISSION_DENIED @ ]</message><errors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="PermissionError"><fieldPath></fieldPath><trigger></trigger><errorString>PermissionError.PERMISSION_DENIED</errorString><reason>PERMISSION_DENIED</reason></errors></ApiExceptionFault></detail></soap:Fault></soap:Body></soap:Envelope>

Here is the code to replicate

<?php

use Google\AdsApi\AdManager\Util\v202302\StatementBuilder;
use Illuminate\Support\Facades\Log;

$ini = parse_ini_file(resource_path('adsapi_php.ini'), true);

$ini['OAUTH2']['jsonKeyFilePath'] = resource_path($ini['OAUTH2']['jsonKeyFilePath']);

$configuration = new Configuration($ini);

$oAuth2Credential = (new OAuth2TokenBuilder())
    ->from($configuration)
    ->build();

// Construct an API session configured from an `adsapi_php.ini` file
// and the OAuth2 credentials above.
$this->session = (new AdManagerSessionBuilder())->from($configuration)
    ->withOAuth2Credential($oAuth2Credential)
    ->build();

$this->serviceFactory = new ServiceFactory();

$creativeService = $this->serviceFactory->createCreativeService($this->session);

$creativeService = $this->serviceFactory->createCreativeService($this->session);

$statementBuilder = (new StatementBuilder())->where('id = :id')
    ->limit(1)
    ->withBindVariableValue('id', CREATIVEIDHERE);

$page = $creativeService->getCreativesByStatement(
    $statementBuilder->toStatement()
);
//this is producing the correct creative
Log::info(sprintf("Found %s Creatives with id %s", count($page->getResults()), $creative->provider_id));

$action = new ActivateCreatives();
$result = $creativeService->performCreativeAction(
    $action,
    $statementBuilder->toStatement();
);

Permissions for the service account are set to administrator. I can activate the line item and the order, but Creative will not activate/deactivate. Alternatively, if it's possible to enable/disable a creative another way, that would be great.

PierrickVoulet commented 1 year ago

Hi @illusive-ch - This issue seems related to the Ad Manager API itself, not the client library. Please contact their support by emailing admanagerapi-support@google.com.