2017-05-05 99 views
2

在使用google-api-php-client庫上傳離線轉化到DoubleClick Search時遇到以下錯誤。使用google-api-php-client在DoubleClick Search API中遇到空批次錯誤

Fatal error: Uncaught exception 'Google_Service_Exception' with message '{ "error": { "errors": [ { "domain": "global", "reason": "requestValidation", "message": "The request was not valid. Details: [Empty batch encountered.]" } ], "code": 400, "message": "The request was not valid. Details: [Empty batch encountered.]" } } ' in /var/www/ds3/vendor/google/apiclient/src/Google/Http/REST.php:118 Stack trace: #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 [internal function]: 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/Google/Client.php(788) in /var/www/ds3/vendor/google/apiclient/src/Google/Http/REST.php on line 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); 
+0

鏈接回到https://github.com/google/google-api-php-client/issues/1213 – DaImTo

回答

0

今天我花了一段時間 - 但我想我是能夠重新創建您的問題並找到解決辦法。麻煩在於轉換列表的構建方式。

以您目前的做法,你會得到一個對象,它看起來像:

{ 
    { 
     "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