Hi,
I am trying to modify the AD of the MultiAssetResponsiveDisplayAd type
using PHP library.
There is an error when I try to create YouTubeVideoAsset and update that
part. Please let me know if there is a solution.
I attached the source code and error code, so please check it.
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads 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 and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/edbe078f-28e7-42dc-b43f-a85a34779bb0n%40googlegroups.com.
<?php
/**
* Copyright 2017 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Google\AdsApi\Examples\AdWords\v201809\DboundUpdate;
require __DIR__ . '/../../../../vendor/autoload.php';
use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\AdWords\v201809\cm\AdOperation;
use Google\AdsApi\AdWords\v201809\cm\AdService;
use Google\AdsApi\AdWords\v201809\cm\AssetLink;
use Google\AdsApi\AdWords\v201809\cm\AssetOperation;
use Google\AdsApi\AdWords\v201809\cm\AssetService;
use Google\AdsApi\AdWords\v201809\cm\DisplayAdFormatSetting;
use Google\AdsApi\AdWords\v201809\cm\ImageAsset;
use Google\AdsApi\AdWords\v201809\cm\MultiAssetResponsiveDisplayAd;
use Google\AdsApi\AdWords\v201809\cm\Operator;
use Google\AdsApi\AdWords\v201809\cm\TextAsset;
use Google\AdsApi\AdWords\v201809\cm\YouTubeVideoAsset;
use Google\AdsApi\Common\OAuth2TokenBuilder;
class SetDisplayAdUpdate
{
const PAGE_LIMIT = 1000;
public static function runExample(
AdWordsServices $adWordsServices,
AdWordsSessionBuilder $sessionBuilder,
$customerId,
$campaignId,
$adgroupId,
$adId,
$datas
)
{
$rows = json_decode($datas);
$session = $sessionBuilder->build();
$assetService = $adWordsServices->get($session, AssetService::class);
$adService = $adWordsServices->get($session, AdService::class);
$operations = [];
$multiAssetResponsiveDisplayAd = new MultiAssetResponsiveDisplayAd();
$multiAssetResponsiveDisplayAd->setId($adId);
if(!empty($rows->adTitle)){
/*for($i=0;$i<count($rows->adTitle);$i++){
$headlineTextAsset[$i] = new TextAsset();
$headlineTextAsset[$i]->setAssetText($rows->adTitle[$i]);
}
$AssetLink = implode(",", new AssetLink($headlineTextAsset));
$multiAssetResponsiveDisplayAd->setHeadlines([$AssetLink]);*/
$headlineTextAsset1 = new TextAsset();
$headlineTextAsset1->setAssetText('제목 테스트 1');
$multiAssetResponsiveDisplayAd->setHeadlines([new
AssetLink($headlineTextAsset1)]);
}
if(!empty($rows->businessName)){
$multiAssetResponsiveDisplayAd->setBusinessName($rows->businessName);
}
if(!empty($rows->adLongTitle)){
$longHeadlineTextAsset = new TextAsset();
$longHeadlineTextAsset->setAssetText($rows->adLongTitle);
$multiAssetResponsiveDisplayAd->setLongHeadline(new
AssetLink($longHeadlineTextAsset));
}
if(!empty($rows->adDescription)){
$descriptionTextAsset1 = new TextAsset();
$descriptionTextAsset1->setAssetText('description1');
$descriptionTextAsset2 = new TextAsset();
$descriptionTextAsset2->setAssetText('description2');
$multiAssetResponsiveDisplayAd->setDescriptions([
new AssetLink($descriptionTextAsset1),
new AssetLink($descriptionTextAsset2)
]);
}
if(!empty($rows->youtubeId)){
$youtubeAsset1 = new YouTubeVideoAsset();
$youtubeAsset1->setAssetId(
self::uploadYoutubeAsset($assetService, '5ADvYJjT1qk')
);
$multiAssetResponsiveDisplayAd->setYouTubeVideos([
new AssetLink($youtubeAsset1)
]);
}
// Set a marketing image.
$marketingImageAsset = new ImageAsset();
$marketingImageAsset->setAssetId(
self::uploadImageAsset($assetService,
'https://tpc.googlesyndication.com/simgad/5271890791481984862')
);
$multiAssetResponsiveDisplayAd->setMarketingImages([
new AssetLink(
$marketingImageAsset
)
]);
// Set a square image.
$squareImageAsset = new ImageAsset();
$squareImageAsset->setAssetId(
self::uploadImageAsset($assetService,
'https://tpc.googlesyndication.com/simgad/2613031290722116919')
);
$multiAssetResponsiveDisplayAd->setSquareMarketingImages([
new AssetLink(
$squareImageAsset
)
]);
if(!empty($rows->finalUrls)){
$url = (strpos($rows->finalUrls, "http://") !== false ||
strpos($rows->finalUrls, "https://") !==
false)?$rows->finalUrls:"http://".$rows->finalUrls;
$multiAssetResponsiveDisplayAd->setFinalUrls([$url]);
}
if(!empty($rows->callToActionText)){
$multiAssetResponsiveDisplayAd->setCallToActionText($rows->callToActionText);
}
if(!empty($rows->mainColor)){
$multiAssetResponsiveDisplayAd->setMainColor($rows->mainColor);
}
if(!empty($rows->accentColor)) {
$multiAssetResponsiveDisplayAd->setAccentColor($rows->accentColor);
}
if(!empty($rows->allowFlexibleColor)){
$multiAssetResponsiveDisplayAd->setAllowFlexibleColor(true);
}else{
$multiAssetResponsiveDisplayAd->setAllowFlexibleColor(false);
}
$operation = new AdOperation();
$operation->setOperand($multiAssetResponsiveDisplayAd);
$operation->setOperator(Operator::SET);
$operations[] = $operation;
$result = $adService->mutate($operations);
return $result;
}
private static function uploadImageAsset(AssetService $assetService, $url)
{
$imageAsset = new ImageAsset();
$imageAsset->setImageData(file_get_contents($url));
$operation = new AssetOperation();
$operation->setOperand($imageAsset);
$operation->setOperator(Operator::ADD);
return $assetService->mutate([$operation])->getValue()[0]->getAssetId();
}
private static function uploadYoutubeAsset(AssetService $assetService,
$youtubeId)
{
$youtubeAsset = new YouTubeVideoAsset();
$youtubeAsset->setYouTubeVideoId($youtubeId);
$operation = new AssetOperation();
$operation->setOperand($youtubeAsset);
$operation->setOperator(Operator::ADD);
return $assetService->mutate([$operation])->getValue()[0]->getAssetId();
}
public static function main($clientCustomerId, $campaignId, $adgroupId,
$adId, $datas)
{
// Generate a refreshable OAuth2 credential for authentication.
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
// See: AdWordsSessionBuilder for setting a client customer ID that is
// different from that specified in your adsapi_php.ini file.
//$sessionBuilder = (new
AdWordsSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential);
$builder = (new
AdWordsSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential);
// clientCustomerId 재지정
if($clientCustomerId!='')
$builder->withClientCustomerId($clientCustomerId); // 고객사 customerID
$sessionBuilder = $builder;
try{
$rs = self::runExample(
new AdWordsServices(),
$sessionBuilder,
$clientCustomerId,
intval($campaignId),
intval($adgroupId),
intval($adId),
$datas
);
echo json_encode($rs);
} catch (ApiException $apiException) {
echo json_encode($apiException->getMessage());
}
}
}
$clientCustomerId = $argv[1];
$campaignId = $argv[2];
$adgroupId = $argv[3];
$adId = $argv[4];
$datas = $argv[5];
SetDisplayAdUpdate::main($clientCustomerId,$campaignId,$adgroupId,$adId,$datas);[2020-11-11T12:05:54.219841+09:00] AW_SOAP.WARNING: clientCustomerId=5073046955
operations=1 service=AdService method=mutate responseTime=258
requestId=0005b3cc12cfc4490a6258c7fb02a7d3 server=adwords.google.com isFault=1
faultMessage=[RequiredError.REQUIRED @
operations[0].operand.youtubeVideos[0].asset.youtubeVideoId]
[2020-11-11T12:05:54.219905+09:00] AW_SOAP.NOTICE: POST
/api/adwords/cm/v201809/AdService?wsdl HTTP/1.1
Host: adwords.google.com
Connection: close
User-Agent: PHP-SOAP/7.3.18
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Content-Length: 2096
Authorization: REDACTED
<?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/v201809"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Header><ns1:RequestHeader><ns1:clientCustomerId>5073046955</ns1:clientCustomerId><ns1:developerToken>REDACTED</ns1:developerToken><ns1:userAgent>unknown
(AwApi-PHP, googleads-php-lib/47.0.0,
PHP/7.3.18)</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
xsi:type="ns1:MultiAssetResponsiveDisplayAd"><ns1:id>463042065303</ns1:id><ns1:finalUrls>http://dev-operation.hada.ai/</ns1:finalUrls><ns1:marketingImages><ns1:asset
xsi:type="ns1:ImageAsset"><ns1:assetId>10553840546</ns1:assetId></ns1:asset></ns1:marketingImages><ns1:squareMarketingImages><ns1:asset
xsi:type="ns1:ImageAsset"><ns1:assetId>10553840549</ns1:assetId></ns1:asset></ns1:squareMarketingImages><ns1:headlines><ns1:asset
xsi:type="ns1:TextAsset"><ns1:assetText>제목 테스트
1</ns1:assetText></ns1:asset></ns1:headlines><ns1:longHeadline><ns1:asset
xsi:type="ns1:TextAsset"><ns1:assetText>리드-디스플레이광고긴제목1</ns1:assetText></ns1:asset></ns1:longHeadline><ns1:descriptions><ns1:asset
xsi:type="ns1:TextAsset"><ns1:assetText>description1</ns1:assetText></ns1:asset></ns1:descriptions><ns1:descriptions><ns1:asset
xsi:type="ns1:TextAsset"><ns1:assetText>description2</ns1:assetText></ns1:asset></ns1:descriptions><ns1:youTubeVideos><ns1:asset
xsi:type="ns1:YouTubeVideoAsset"><ns1:assetId>12066652108</ns1:assetId></ns1:asset></ns1:youTubeVideos><ns1:businessName>디바운드</ns1:businessName><ns1:mainColor>#ffffff</ns1:mainColor><ns1:accentColor>#000000</ns1:accentColor><ns1:allowFlexibleColor>true</ns1:allowFlexibleColor><ns1:callToActionText>자세히
알아보기</ns1:callToActionText></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: Wed, 11 Nov 2020 03:05:54 GMT
Expires: Wed, 11 Nov 2020 03:05:54 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Content-Security-Policy: frame-ancestors 'self'
X-XSS-Protection: 1; mode=block
Server: GSE
Alt-Svc: h3-Q050=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-T051=":443";
ma=2592000,h3-T050=":443"; ma=2592000,h3-Q046=":443";
ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
Accept-Ranges: none
Vary: Accept-Encoding
Connection: close
Transfer-Encoding: chunked
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><ResponseHeader
xmlns="https://adwords.google.com/api/adwords/cm/v201809"><requestId>0005b3cc12cfc4490a6258c7fb02a7d3</requestId><serviceName>AdService</serviceName><methodName>mutate</methodName><operations>1</operations><responseTime>258</responseTime></ResponseHeader></soap:Header><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>[RequiredError.REQUIRED
@
operations[0].operand.youtubeVideos[0].asset.youtubeVideoId]</faultstring><detail><ApiExceptionFault
xmlns="https://adwords.google.com/api/adwords/cm/v201809"><message>[RequiredError.REQUIRED
@
operations[0].operand.youtubeVideos[0].asset.youtubeVideoId]</message><ApplicationException.Type>ApiException</ApplicationException.Type><errors
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="RequiredError"><fieldPath>operations[0].operand.youtubeVideos[0].asset.youtubeVideoId</fieldPath><fieldPathElements><field>operations</field><index>0</index></fieldPathElements><fieldPathElements><field>operand</field></fieldPathElements><fieldPathElements><field>youtubeVideos</field><index>0</index></fieldPathElements><fieldPathElements><field>asset</field></fieldPathElements><fieldPathElements><field>youtubeVideoId</field></fieldPathElements><trigger></trigger><errorString>RequiredError.REQUIRED</errorString><ApiError.Type>RequiredError</ApiError.Type><reason>REQUIRED</reason></errors></ApiExceptionFault></detail></soap:Fault></soap:Body></soap:Envelope>
PHP Fatal error: Uncaught Google\AdsApi\AdWords\v201809\cm\ApiException:
[RequiredError.REQUIRED @
operations[0].operand.youtubeVideos[0].asset.youtubeVideoId] in
/home/gitlab-runner/www/adcms/vendor/google/src/Google/AdsApi/Common/Util/Reflection.php:43
Stack trace:
#0
/home/gitlab-runner/www/adcms/vendor/google/src/Google/AdsApi/Common/Util/Reflection.php(43):
ReflectionClass->newInstanceArgs(Array)
#1
/home/gitlab-runner/www/adcms/vendor/google/src/Google/AdsApi/Common/AdsSoapClient.php(202):
Google\AdsApi\Common\Util\Reflection->createInstance('Google\\AdsApi\\A...',
Array)
#2
/home/gitlab-runner/www/adcms/vendor/google/src/Google/AdsApi/Common/AdsSoapClient.php(164):
Google\AdsApi\Common\AdsSoapClient->parseApiExceptionFromSoapFault(Object(SoapFault))
#3
/home/gitlab-runner/www/adcms/vendor/google/src/Google/AdsApi/AdWords/v201809/cm/AdService.php(191):
Google\AdsApi\Common\AdsSoapClient->__soapCall('mutate', Array)
#4
/home/gitlab-runner/www/adcms/vendor/google/examples/AdWords/v201809/DboundUpdate/SetDisplayAdUpdate.ph
in
/home/gitlab-runner/www/adcms/vendor/google/src/Google/AdsApi/Common/Util/Reflection.php
on line 43