php - 尝试在google api(php)中为app_ad变异创建AdGroupAd时如何解决分段错误
问题描述
我正在尝试使用现有的 groupAd 创建一个 AdGroupAd,并且我收到了“segmentation fault”错误消息我已经处理了一天多,但是缺少有关错误的详细信息只会让这很疯狂了解什么是错的
在码头上运行
客户端库:v5.0.0
谷歌广告 API:v5.0
PHP 7.4.12 (cli) (构建: Nov 5 2020 20:24:10) (NTS)
Zend 引擎 v3.4.0,
ionCube PHP 加载器 + ionCube24 v10.4.4
Zend OPcache v7.4.12
原型buff 3.14.0
grpc 1.33.1
我的代码:假设在 $adGroup 参数中使用 adGroup 的有效资源名称调用 createAdGroupAd(),并且在这种情况下类型是 CreativeType_Asset::TYPE_YOUTUBE(尽管我尝试了两种类型并且都给出了错误)
public function createAdGroupAd($adGroup, $data) {
$service = $this->client->getAdGroupAdServiceClient();
$ad = $this->createAd($data, $data['asset']->type);
$adGroupAd = new AdGroupAd([
'ad' => $ad,
'status' => AdGroupAdStatus::PAUSED,
'ad_group' => $adGroup
]);
$adGroupAdOperation = new AdGroupAdOperation();
$adGroupAdOperation->setCreate($adGroupAd);
//this is the call causing the error
$response = $service->mutateAdGroupAds(
$this->customerId,
[$adGroupAdOperation]
);
return $response->getResults()->count() > 0 ? $response->getResults()[0]->getResourceName() : null;
}
public function createAd($data, $adType = null) {
$service = $this->client->getAdServiceClient();
$appAdInfo = new AppAdInfo([
'headlines' => array_map(function ($headline) {
new AdTextAsset(['text' => $headline]);
}, [$data['creative']->title1, $data['creative']->title2]),
'descriptions' => array_map(function ($description) {
new AdTextAsset(['text' => $description]);
}, [$data['creative']->description1, $data['creative']->description2])
]);
switch ($adType) {
case CreativeType_Asset::TYPE_IMAGE:
$appAdInfo->setImages([new AdImageAsset(['asset' => $data['assetResourceName']])]);
break;
case CreativeType_Asset::TYPE_YOUTUBE:
$appAdInfo->setYoutubeVideos([new AdVideoAsset(['asset' => $data['assetResourceName']])]);
break;
default:
break;
}
return new Ad([
'app_ad' => $appAdInfo,
'type' => AdType::APP_AD]);
}
解决方案
问题是 AppAdInfo 构建部分的 array_map 函数中缺少“return”语句。
推荐阅读
- haskell - 对列表中的一对列表 Haskell
- reactjs - 使用 HOC、React Context 和 componentDidMount API 从 Firebase 获取 uid
- c# - System.Data.SqlClient.SqlException:''('.' 附近的语法不正确。'
- java - 在 Spring Web 应用程序中创建自定义 JSONresponse
- javascript - 比较数组并添加?
- angular - 如何在我的 ionic4 应用程序中检索特定的详细信息
- elasticsearch - Kibana 6.5.4 创建索引模式卡住
- python - Pandas 从列名不同的行中选择数据
- ios - 在另一个类中使用用户选择的结构
- python - 如何在运行时将队列添加到自定义消息使用者