空批次在使用 google-api-php-client 的 DoubleClick Search API 中遇到错误
Posted
技术标签:
【中文标题】空批次在使用 google-api-php-client 的 DoubleClick Search API 中遇到错误【英文标题】:Empty batch encountered error in DoubleClick Search API using google-api-php-client 【发布时间】:2017-10-03 17:34:38 【问题描述】:在使用 google-api-php-client 库将离线转化上传到 DoubleClick Search 时,我遇到了以下错误。
致命错误:未捕获的异常 'Google_Service_Exception' 带有消息 ' "error": "errors": [ "domain": "global", "reason": "requestValidation", "message": "The request was无效。详细信息:[遇到空批次。]" ],"代码":400,"消息":"请求无效。详细信息:[遇到空批次。]" ' in /var/www/ ds3/vendor/google/apiclient/src/Google/Http/REST.php:118 堆栈跟踪:#0 /var/www/ds3/vendor/google/apiclient/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #1 [内部函数]: Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object (GuzzleHttp\Psr7\Request), 'Google_Service_...') #2 /var/www/ds3/vendor/google/apiclient/src/Google/Task/Runner.php(176): call_user_func_array(Array, Array) # 3 /var/www/ds3/vendor/google/apiclient/src/Google/Http/REST.php(58): Google_Task_Runner->run() #4 /var/www/ds3/vendor/google/apiclient/src/谷歌/CLI /var/www/ds3/vendor/google/apiclient/src/Google/Http/REST.php 中的 ent.php(788) 第 118 行
使用以下代码插入新的转换
putenv('GOOGLE_APPLICATION_CREDENTIALS=PATH_TO_SERVICE_ACCOUNT_JSONFILE.json');
$Client = new Google_Client();
$Client->useApplicationDefaultCredentials();
$Client->addScope(Google_Service_Doubleclicksearch::DOUBLECLICKSEARCH);
$DS3 = new Google_Service_Doubleclicksearch($Client);
$Conversion = new Google_Service_Doubleclicksearch_Conversion();
$Conversion->setClickId('MY_GCLID');
$Conversion->setConversionId('MY_CONV_ID');
$Conversion->setConversionTimestamp('MY_CONV_TIMESTAMP');
$Conversion->setSegmentationType('FLOODLIGHT');
$Conversion->setSegmentationName('MY_FLOODLIGHT_ACTIVITY_NAME');
$Conversion->setSegmentationType('ACTION');
$ConversionList = new Google_Service_Doubleclicksearch_ConversionList();
$ConversionList->setConversion($Conversion);
$Response = $DS3->conversion->insert($ConversionList);
print_r($Response);
【问题讨论】:
链接回github.com/google/google-api-php-client/issues/1213 【参考方案1】:今天花了我一段时间 - 但我想我能够重现您的问题并找到解决方案。问题在于转化列表的构建方式。
使用您当前的方法,您将获得一个类似于以下内容的对象:
"clickId": "MY_GCLID",
"segmentationName": "MY_SEGMENTATION_NAME",
.
.
.
你想要的,是这样的:
"conversion": [
"clickId": "MY_CLICK",
"conversionId": "MY_CONV",
"conversionTimestamp": "MY_TIME",
"currencyCode": "USD",
"revenueMicros": "SOMEMONEY",
"type": "TRANSACTION"
],
"kind": "doubleclicksearch#conversionList"
对代码的更改将围绕列表本身:
$ConversionList = new Google_Service_Doubleclicksearch_ConversionList();
$ConversionList->setKind('doubleclicksearch#conversionList');
$ConversionList['conversion'] = [$Conversion]; // iterator magic
谷歌文档中记录的charles proxy 在
识别有效载荷问题。
Google developr api's 帮助完成了剩下的工作
【讨论】:
以上是关于空批次在使用 google-api-php-client 的 DoubleClick Search API 中遇到错误的主要内容,如果未能解决你的问题,请参考以下文章
PyTorch DataLoader 可以从空数据集开始吗?
SAP MM中采用批次号管理是啥?管理的物料采购这块还是仓管这块?若设置为采用批次号管理,如何在后台配