首页 > 解决方案 > 尝试在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]);
    }

标签: phpsegmentation-faultgoogle-ads-api

解决方案


问题是 AppAdInfo 构建部分的 array_map 函数中缺少“return”语句。


推荐阅读